Merge lp:~schwab-linux-m68k/bzr-fastimport/parentless into lp:bzr-fastimport

Proposed by Andreas Schwab
Status: Needs review
Proposed branch: lp:~schwab-linux-m68k/bzr-fastimport/parentless
Merge into: lp:bzr-fastimport
Diff against target: 46 lines (+1/-19)
1 file modified
exporter.py (+1/-19)
To merge this branch: bzr merge lp:~schwab-linux-m68k/bzr-fastimport/parentless
Reviewer Review Type Date Requested Status
Bazaar Developers Pending
Review via email: mp+105048@code.launchpad.net

Description of the change

The proper way to create a parentless commit is to emit a reset command for the branch
without a following from command. That obviates the need to invent a possibly conflicting
branch name.

To post a comment you must log in.

Unmerged revisions

357. By Andreas Schwab

Properly create parentless commit

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-05-08 09:49:19 +0000
@@ -187,14 +187,11 @@
187187
188 # Load the marks and initialise things accordingly188 # Load the marks and initialise things accordingly
189 self.revid_to_mark = {}189 self.revid_to_mark = {}
190 self.branch_names = {}
191 if self.import_marks_file:190 if self.import_marks_file:
192 marks_info = marks_file.import_marks(self.import_marks_file)191 marks_info = marks_file.import_marks(self.import_marks_file)
193 if marks_info is not None:192 if marks_info is not None:
194 self.revid_to_mark = dict((r, m) for m, r in193 self.revid_to_mark = dict((r, m) for m, r in
195 marks_info.items())194 marks_info.items())
196 # These are no longer included in the marks file
197 #self.branch_names = marks_info[1]
198195
199 def interesting_history(self):196 def interesting_history(self):
200 if self.revision:197 if self.revision:
@@ -339,12 +336,7 @@
339 ncommits = len(self.revid_to_mark)336 ncommits = len(self.revid_to_mark)
340 nparents = len(revobj.parent_ids)337 nparents = len(revobj.parent_ids)
341 if nparents == 0:338 if nparents == 0:
342 if ncommits:339 self.print_cmd(commands.ResetCommand(ref, None))
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_REVISION340 parent = bzrlib.revision.NULL_REVISION
349 else:341 else:
350 parent = revobj.parent_ids[0]342 parent = revobj.parent_ids[0]
@@ -617,13 +609,3 @@
617 'valid in git.', git_ref)609 'valid in git.', git_ref)
618 continue610 continue
619 self.print_cmd(commands.ResetCommand(git_ref, ":" + str(mark)))611 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

Subscribers

People subscribed via source and target branches