diff options
author | Ian Clatworthy <ian.clatworthy@canonical.com> | 2009-07-20 14:53:33 +1000 |
---|---|---|
committer | Ian Clatworthy <ian.clatworthy@canonical.com> | 2009-07-20 14:53:33 +1000 |
commit | b60e977721fae6092698b1eda46c1fb8d610e7df (patch) | |
tree | 1c6a4cd2bc9c550256e7d5cbebf45acb6581d202 | |
parent | 9e0a659f753df4f05e3f9e26ed904c8f70860406 (diff) | |
parent | 407d5310faf029892f257adedf4706ef92c17e42 (diff) | |
download | bzr-fastimport-b60e977721fae6092698b1eda46c1fb8d610e7df.tar.gz |
Here-document style commit messages (Samuel Bronson)
-rw-r--r-- | parser.py | 14 | ||||
-rw-r--r-- | tests/test_parser.py | 14 |
2 files changed, 25 insertions, 3 deletions
@@ -88,7 +88,8 @@ The grammar is: # note: delim may be any string but must not contain lf. # data_line may contain any data but must not be exactly - # delim. + # delim. The lf after the final data_line is included in + # the data. delimited_data ::= 'data' sp '<<' delim lf (data_line lf)* delim lf; @@ -234,7 +235,16 @@ class LineBasedParser(object): :return: the bytes read up to but excluding the terminator. """ - raise NotImplementedError(self.read_until) + + lines = [] + term = terminator + '\n' + while True: + line = self.input.readline() + if line == term: + break + else: + lines.append(line) + return ''.join(lines) # Regular expression used for parsing. (Note: The spec states that the name diff --git a/tests/test_parser.py b/tests/test_parser.py index ac5239e..91e27f0 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -101,6 +101,14 @@ author <bugs@bunny.org> now committer <bugs@bunny.org> now data 20 first commit, empty +# Test a commit with a heredoc-style (delimited_data) messsage (bug #400960) +commit refs/heads/master +mark :4 +author <bugs@bunny.org> now +committer <bugs@bunny.org> now +data <<EOF +Commit with heredoc-style message +EOF """ @@ -115,7 +123,7 @@ class TestImportParser(tests.TestCase): if cmd.name == 'commit': for fc in cmd.file_iter(): result.append(fc) - self.assertEqual(len(result), 10) + self.assertEqual(len(result), 11) cmd1 = result.pop(0) self.assertEqual('progress', cmd1.name) self.assertEqual('completed', cmd1.message) @@ -178,6 +186,10 @@ class TestImportParser(tests.TestCase): self.assertEqual('commit', cmd.name) self.assertEqual('3', cmd.mark) self.assertEqual(None, cmd.from_) + cmd = result.pop(0) + self.assertEqual('commit', cmd.name) + self.assertEqual('4', cmd.mark) + self.assertEqual('Commit with heredoc-style message\n', cmd.message) class TestStringParsing(tests.TestCase): |