Merge lp:~jelmer/brz/line-endings into lp:brz

Proposed by Jelmer Vernooij on 2018-09-21
Status: Merged
Approved by: Jelmer Vernooij on 2018-09-21
Approved revision: 7124
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/line-endings
Merge into: lp:brz
Diff against target: 54 lines (+21/-1)
3 files modified
breezy/bzr/__init__.py (+4/-1)
breezy/errors.py (+9/-0)
breezy/tests/test_bzrdir.py (+8/-0)
To merge this branch: bzr merge lp:~jelmer/brz/line-endings
Reviewer Review Type Date Requested Status
Martin Packman 2018-09-21 Approve on 2018-09-21
Review via email: mp+355463@code.launchpad.net

Description of the change

Improve error message if line endings in format file were corrupted.

To post a comment you must log in.
Martin Packman (gz) wrote :

Seems reasonable, could alternatively only raise this if `klass.formats.get(first_line.replace('\r'))` returns something.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/__init__.py'
2--- breezy/bzr/__init__.py 2018-06-27 20:57:41 +0000
3+++ breezy/bzr/__init__.py 2018-09-21 02:15:40 +0000
4@@ -44,7 +44,10 @@
5 try:
6 cls = klass.formats.get(first_line)
7 except KeyError:
8- raise errors.UnknownFormatError(format=first_line, kind='bzrdir')
9+ if first_line.endswith(b"\r\n"):
10+ raise errors.LineEndingError(file=".bzr/branch-format")
11+ else:
12+ raise errors.UnknownFormatError(format=first_line, kind='bzrdir')
13 return cls.from_string(format_string)
14
15 @classmethod
16
17=== modified file 'breezy/errors.py'
18--- breezy/errors.py 2018-08-14 21:37:46 +0000
19+++ breezy/errors.py 2018-09-21 02:15:40 +0000
20@@ -592,6 +592,15 @@
21 self.format = format
22
23
24+class LineEndingError(BzrError):
25+
26+ _fmt = ("Line ending corrupted for file: %(file)s; "
27+ "Maybe your files got corrupted in transport?")
28+
29+ def __init__(self, file):
30+ self.file = file
31+
32+
33 class IncompatibleFormat(BzrError):
34
35 _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
36
37=== modified file 'breezy/tests/test_bzrdir.py'
38--- breezy/tests/test_bzrdir.py 2018-08-07 20:43:32 +0000
39+++ breezy/tests/test_bzrdir.py 2018-09-21 02:15:40 +0000
40@@ -312,6 +312,14 @@
41 bzrdir.BzrDirFormat.find_format,
42 _mod_transport.get_transport_from_path('.'))
43
44+ def test_find_format_line_endings(self):
45+ t = self.get_transport()
46+ t.mkdir('.bzr')
47+ t.put_bytes('.bzr/branch-format', b'Corrupt line endings\r\n')
48+ self.assertRaises(errors.LineEndingError,
49+ bzrdir.BzrDirFormat.find_format,
50+ _mod_transport.get_transport_from_path('.'))
51+
52 def test_register_unregister_format(self):
53 format = SampleBzrDirFormat()
54 url = self.get_url()

Subscribers

People subscribed via source and target branches