~stewart/bzr-fastimport/misc-fixes-for-git-import

« back to all changes in this revision

Viewing changes to exporter.py

  • Committer: Stewart Smith
  • Date: 2013-09-25 07:25:32 UTC
  • mfrom: (356.1.1 fastimport)
  • Revision ID: stewart@flamingspork.com-20130925072532-m39402fkf50kj2lx
merge bzr merge lp:~a-s-usov/bzr-fastimport/no-temp-branches

Show diffs side-by-side

added added

removed removed

Lines of Context:
317
317
        mark = 1
318
318
        self.revid_to_mark[revid] = mark
319
319
        file_cmds = self._get_filecommands(bzrlib.revision.NULL_REVISION, revid)
 
320
        self.print_cmd(commands.ResetCommand(ref, None))
320
321
        self.print_cmd(self._get_commit_command(ref, mark, revobj, file_cmds))
321
322
 
322
323
    def emit_commit(self, revid, ref):
339
340
        ncommits = len(self.revid_to_mark)
340
341
        nparents = len(revobj.parent_ids)
341
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
343
            parent = bzrlib.revision.NULL_REVISION
349
344
        else:
350
345
            parent = revobj.parent_ids[0]
351
346
 
 
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
352
        # Print the commit
353
353
        mark = ncommits + 1
354
354
        self.revid_to_mark[revid] = mark
617
617
                                     'valid in git.', git_ref)
618
618
                        continue
619
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