summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Bronson <naesten@gmail.com>2009-07-20 22:41:55 -0400
committerSamuel Bronson <naesten@gmail.com>2009-07-20 22:41:55 -0400
commitbfe6449ebe14d89451af0e92708842f090650003 (patch)
tree8f4515a3fa87438151effd9015d722a9312983f8
parenta37ff4974213e0350dbf0b26f0fd473eb0a0bc75 (diff)
parentb60e977721fae6092698b1eda46c1fb8d610e7df (diff)
downloadbzr-fastimport-bfe6449ebe14d89451af0e92708842f090650003.tar.gz
Merge my fix for #400960 back from trunk.
-rw-r--r--parser.py14
-rw-r--r--tests/test_parser.py14
2 files changed, 25 insertions, 3 deletions
diff --git a/parser.py b/parser.py
index 4897fa0..b93fc9d 100644
--- a/parser.py
+++ b/parser.py
@@ -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):