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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
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 Approve
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.
Revision history for this message
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
=== modified file 'breezy/bzr/__init__.py'
--- breezy/bzr/__init__.py 2018-06-27 20:57:41 +0000
+++ breezy/bzr/__init__.py 2018-09-21 02:15:40 +0000
@@ -44,7 +44,10 @@
44 try:44 try:
45 cls = klass.formats.get(first_line)45 cls = klass.formats.get(first_line)
46 except KeyError:46 except KeyError:
47 raise errors.UnknownFormatError(format=first_line, kind='bzrdir')47 if first_line.endswith(b"\r\n"):
48 raise errors.LineEndingError(file=".bzr/branch-format")
49 else:
50 raise errors.UnknownFormatError(format=first_line, kind='bzrdir')
48 return cls.from_string(format_string)51 return cls.from_string(format_string)
4952
50 @classmethod53 @classmethod
5154
=== modified file 'breezy/errors.py'
--- breezy/errors.py 2018-08-14 21:37:46 +0000
+++ breezy/errors.py 2018-09-21 02:15:40 +0000
@@ -592,6 +592,15 @@
592 self.format = format592 self.format = format
593593
594594
595class LineEndingError(BzrError):
596
597 _fmt = ("Line ending corrupted for file: %(file)s; "
598 "Maybe your files got corrupted in transport?")
599
600 def __init__(self, file):
601 self.file = file
602
603
595class IncompatibleFormat(BzrError):604class IncompatibleFormat(BzrError):
596605
597 _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."606 _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
598607
=== modified file 'breezy/tests/test_bzrdir.py'
--- breezy/tests/test_bzrdir.py 2018-08-07 20:43:32 +0000
+++ breezy/tests/test_bzrdir.py 2018-09-21 02:15:40 +0000
@@ -312,6 +312,14 @@
312 bzrdir.BzrDirFormat.find_format,312 bzrdir.BzrDirFormat.find_format,
313 _mod_transport.get_transport_from_path('.'))313 _mod_transport.get_transport_from_path('.'))
314314
315 def test_find_format_line_endings(self):
316 t = self.get_transport()
317 t.mkdir('.bzr')
318 t.put_bytes('.bzr/branch-format', b'Corrupt line endings\r\n')
319 self.assertRaises(errors.LineEndingError,
320 bzrdir.BzrDirFormat.find_format,
321 _mod_transport.get_transport_from_path('.'))
322
315 def test_register_unregister_format(self):323 def test_register_unregister_format(self):
316 format = SampleBzrDirFormat()324 format = SampleBzrDirFormat()
317 url = self.get_url()325 url = self.get_url()

Subscribers

People subscribed via source and target branches