Merge lp:~a-s-usov/bzr-fastimport/no-temp-branches into lp:bzr-fastimport

Proposed by Alex Usov
Status: Needs review
Proposed branch: lp:~a-s-usov/bzr-fastimport/no-temp-branches
Merge into: lp:bzr-fastimport
Diff against target: 70 lines (+9/-18)
2 files modified
exporter.py (+6/-16)
tests/test_commands.py (+3/-2)
To merge this branch: bzr merge lp:~a-s-usov/bzr-fastimport/no-temp-branches
Reviewer Review Type Date Requested Status
Bazaar Developers Pending
Review via email: mp+123127@code.launchpad.net

Description of the change

Correct way to emit "parentless" commit is by issuing reset command, not by creating a temporary branch for it.

To post a comment you must log in.

Unmerged revisions

357. By Oleksandr Usov <email address hidden>

Emit 'reset' command for parentless & baseline commits.
This solves exporting branches with multiple roots without
resorting to use temporary branches

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'exporter.py'
--- exporter.py 2012-02-28 16:16:13 +0000
+++ exporter.py 2012-09-06 16:58:20 +0000
@@ -317,6 +317,7 @@
317 mark = 1317 mark = 1
318 self.revid_to_mark[revid] = mark318 self.revid_to_mark[revid] = mark
319 file_cmds = self._get_filecommands(bzrlib.revision.NULL_REVISION, revid)319 file_cmds = self._get_filecommands(bzrlib.revision.NULL_REVISION, revid)
320 self.print_cmd(commands.ResetCommand(ref, None))
320 self.print_cmd(self._get_commit_command(ref, mark, revobj, file_cmds))321 self.print_cmd(self._get_commit_command(ref, mark, revobj, file_cmds))
321322
322 def emit_commit(self, revid, ref):323 def emit_commit(self, revid, ref):
@@ -339,16 +340,15 @@
339 ncommits = len(self.revid_to_mark)340 ncommits = len(self.revid_to_mark)
340 nparents = len(revobj.parent_ids)341 nparents = len(revobj.parent_ids)
341 if nparents == 0:342 if nparents == 0:
342 if ncommits:
343 # This is a parentless commit but it's not the first one
344 # output. We need to create a new temporary branch for it
345 # otherwise git-fast-import will assume the previous commit
346 # was this one's parent
347 ref = self._next_tmp_ref()
348 parent = bzrlib.revision.NULL_REVISION343 parent = bzrlib.revision.NULL_REVISION
349 else:344 else:
350 parent = revobj.parent_ids[0]345 parent = revobj.parent_ids[0]
351346
347 # For parentless commits we need to issue reset command first, otherwise
348 # git-fast-import will assume previous commit was this one's parent
349 if nparents == 0:
350 self.print_cmd(commands.ResetCommand(ref, None))
351
352 # Print the commit352 # Print the commit
353 mark = ncommits + 1353 mark = ncommits + 1
354 self.revid_to_mark[revid] = mark354 self.revid_to_mark[revid] = mark
@@ -617,13 +617,3 @@
617 'valid in git.', git_ref)617 'valid in git.', git_ref)
618 continue618 continue
619 self.print_cmd(commands.ResetCommand(git_ref, ":" + str(mark)))619 self.print_cmd(commands.ResetCommand(git_ref, ":" + str(mark)))
620
621 def _next_tmp_ref(self):
622 """Return a unique branch name. The name will start with "tmp"."""
623 prefix = 'tmp'
624 if prefix not in self.branch_names:
625 self.branch_names[prefix] = 0
626 else:
627 self.branch_names[prefix] += 1
628 prefix = '%s.%d' % (prefix, self.branch_names[prefix])
629 return 'refs/heads/%s' % prefix
630620
=== modified file 'tests/test_commands.py'
--- tests/test_commands.py 2012-03-01 21:17:18 +0000
+++ tests/test_commands.py 2012-09-06 16:58:20 +0000
@@ -59,7 +59,8 @@
59 self.assertIsNot("bla", stream.read())59 self.assertIsNot("bla", stream.read())
6060
6161
62fast_export_baseline_data = """commit refs/heads/master62fast_export_baseline_data = """reset refs/heads/master
63commit refs/heads/master
63mark :164mark :1
64committer65committer
65data 1566data 15
@@ -103,7 +104,7 @@
103 tree = self.make_branch_and_tree("br")104 tree = self.make_branch_and_tree("br")
104 tree.commit("pointless")105 tree.commit("pointless")
105 data = self.run_bzr("fast-export br")[0]106 data = self.run_bzr("fast-export br")[0]
106 self.assertTrue(data.startswith('commit refs/heads/master\nmark :1\ncommitter'))107 self.assertTrue(data.startswith('reset refs/heads/master\ncommit refs/heads/master\nmark :1\ncommitter'))
107108
108 def test_file(self):109 def test_file(self):
109 tree = self.make_branch_and_tree("br")110 tree = self.make_branch_and_tree("br")

Subscribers

People subscribed via source and target branches