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

Proposed by Alex Usov on 2012-09-06
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 2012-09-06 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> on 2012-08-21

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
1=== modified file 'exporter.py'
2--- exporter.py 2012-02-28 16:16:13 +0000
3+++ exporter.py 2012-09-06 16:58:20 +0000
4@@ -317,6 +317,7 @@
5 mark = 1
6 self.revid_to_mark[revid] = mark
7 file_cmds = self._get_filecommands(bzrlib.revision.NULL_REVISION, revid)
8+ self.print_cmd(commands.ResetCommand(ref, None))
9 self.print_cmd(self._get_commit_command(ref, mark, revobj, file_cmds))
10
11 def emit_commit(self, revid, ref):
12@@ -339,16 +340,15 @@
13 ncommits = len(self.revid_to_mark)
14 nparents = len(revobj.parent_ids)
15 if nparents == 0:
16- if ncommits:
17- # This is a parentless commit but it's not the first one
18- # output. We need to create a new temporary branch for it
19- # otherwise git-fast-import will assume the previous commit
20- # was this one's parent
21- ref = self._next_tmp_ref()
22 parent = bzrlib.revision.NULL_REVISION
23 else:
24 parent = revobj.parent_ids[0]
25
26+ # For parentless commits we need to issue reset command first, otherwise
27+ # git-fast-import will assume previous commit was this one's parent
28+ if nparents == 0:
29+ self.print_cmd(commands.ResetCommand(ref, None))
30+
31 # Print the commit
32 mark = ncommits + 1
33 self.revid_to_mark[revid] = mark
34@@ -617,13 +617,3 @@
35 'valid in git.', git_ref)
36 continue
37 self.print_cmd(commands.ResetCommand(git_ref, ":" + str(mark)))
38-
39- def _next_tmp_ref(self):
40- """Return a unique branch name. The name will start with "tmp"."""
41- prefix = 'tmp'
42- if prefix not in self.branch_names:
43- self.branch_names[prefix] = 0
44- else:
45- self.branch_names[prefix] += 1
46- prefix = '%s.%d' % (prefix, self.branch_names[prefix])
47- return 'refs/heads/%s' % prefix
48
49=== modified file 'tests/test_commands.py'
50--- tests/test_commands.py 2012-03-01 21:17:18 +0000
51+++ tests/test_commands.py 2012-09-06 16:58:20 +0000
52@@ -59,7 +59,8 @@
53 self.assertIsNot("bla", stream.read())
54
55
56-fast_export_baseline_data = """commit refs/heads/master
57+fast_export_baseline_data = """reset refs/heads/master
58+commit refs/heads/master
59 mark :1
60 committer
61 data 15
62@@ -103,7 +104,7 @@
63 tree = self.make_branch_and_tree("br")
64 tree.commit("pointless")
65 data = self.run_bzr("fast-export br")[0]
66- self.assertTrue(data.startswith('commit refs/heads/master\nmark :1\ncommitter'))
67+ self.assertTrue(data.startswith('reset refs/heads/master\ncommit refs/heads/master\nmark :1\ncommitter'))
68
69 def test_file(self):
70 tree = self.make_branch_and_tree("br")

Subscribers

People subscribed via source and target branches