From 92f2aa6376edd1518e89c2180b011715b5053e98 Mon Sep 17 00:00:00 2001 From: Andy Grimm Date: Tue, 22 Nov 2011 15:28:59 -0500 Subject: fix --baseline bugs, and add a couple of tests --- cmds.py | 2 +- exporter.py | 16 +++++------ tests/test_commands.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 9 deletions(-) diff --git a/cmds.py b/cmds.py index a92e326..dff6d3c 100644 --- a/cmds.py +++ b/cmds.py @@ -667,7 +667,7 @@ class cmd_fast_export(Command): " (plain mode only).", ), Option('baseline', - help="Export an 'abolute' baseline commit prior to" + help="Export an 'absolute' baseline commit prior to" "the first relative commit", ), ] diff --git a/exporter.py b/exporter.py index b5c6651..2094ff5 100644 --- a/exporter.py +++ b/exporter.py @@ -215,6 +215,10 @@ class BzrFastExporter(object): self.note("Calculating the revisions to exclude ...") self.excluded_revisions = set([rev_id for rev_id, _, _, _ in self.branch.iter_merge_sorted_revisions(start_rev_id)]) + if self.baseline: + # needed so the first relative commit knows its parent + self.excluded_revisions.remove(start_rev_id) + view_revisions.insert(0, start_rev_id) return list(view_revisions) def run(self): @@ -228,8 +232,7 @@ class BzrFastExporter(object): if not self.plain_format: self.emit_features() if self.baseline: - self._commit_total += 1 - self.emit_baseline(interesting[0], self.git_branch) + self.emit_baseline(interesting.pop(0), self.git_branch) for revid in interesting: self.emit_commit(revid, self.git_branch) if self.branch.supports_tags(): @@ -311,13 +314,10 @@ class BzrFastExporter(object): # Emit a full source tree of the first commit's parent git_ref = 'refs/heads/%s' % (git_branch,) revobj = self.branch.repository.get_revision(revid) - assert(len(revobj.parent_ids)) - previd = revobj.parent_ids[0] - prevobj = self.branch.repository.get_revision(previd) mark = 1 - self.revid_to_mark[previd] = mark - file_cmds = self._get_filecommands(bzrlib.revision.NULL_REVISION, previd) - self.print_cmd(self._get_commit_command(git_ref, mark, prevobj, + self.revid_to_mark[revid] = mark + file_cmds = self._get_filecommands(bzrlib.revision.NULL_REVISION, revid) + self.print_cmd(self._get_commit_command(git_ref, mark, revobj, file_cmds)) def emit_commit(self, revid, git_branch): diff --git a/tests/test_commands.py b/tests/test_commands.py index 5729660..5053416 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -16,6 +16,7 @@ """Test the command implementations.""" import os +import re import tempfile import gzip @@ -58,6 +59,40 @@ class TestSourceStream(tests.TestCase): self.assertIsNot("bla", stream.read()) +fast_export_baseline_data = """commit refs/heads/master +mark :1 +committer +data 15 +add c, remove b +M 644 inline a +data 13 +test 1 +test 3 +M 644 inline c +data 6 +test 4 +commit refs/heads/master +mark :2 +committer +data 14 +modify a again +from :1 +M 644 inline a +data 20 +test 1 +test 3 +test 5 +commit refs/heads/master +mark :3 +committer +data 5 +add d +from :2 +M 644 inline d +data 6 +test 6 +""" + class TestFastExport(ExternalBase): def test_empty(self): @@ -99,6 +134,45 @@ class TestFastExport(ExternalBase): # "bad Tag" should be exported as bad_Tag self.assertNotEqual(-1, data.find("reset refs/tags/bad_Tag")) + def test_baseline_option(self): + tree = self.make_branch_and_tree("bl") + + # Revision 1 + file('bl/a', 'w').write('test 1') + tree.add('a') + tree.commit(message='add a') + + # Revision 2 + file('bl/b', 'w').write('test 2') + file('bl/a', 'a').write('\ntest 3') + tree.add('b') + tree.commit(message='add b, modify a') + + # Revision 3 + file('bl/c', 'w').write('test 4') + tree.add('c') + tree.remove('b') + tree.commit(message='add c, remove b') + + # Revision 4 + file('bl/a', 'a').write('\ntest 5') + tree.commit(message='modify a again') + + # Revision 5 + file('bl/d', 'w').write('test 6') + tree.add('d') + tree.commit(message='add d') + + # This exports the baseline state at Revision 3, + # followed by the deltas for 4 and 5 + data = self.run_bzr("fast-export --baseline -r 3.. bl")[0] + data = re.sub('committer.*', 'committer', data) + self.assertEquals(fast_export_baseline_data, data) + + # Also confirm that --baseline with no args is identical to full export + data1 = self.run_bzr("fast-export --baseline bl")[0] + data2 = self.run_bzr("fast-export bl")[0] + self.assertEquals(data1, data2) simple_fast_import_stream = """commit refs/heads/master mark :1 -- cgit v1.2.1