- pidx1, pidx2 = 0, 1
- if parents[1] > 0:
- if parents[0] <= 0 or \
- repo.changelog.node(parents[0]) < repo.changelog.node(parents[1]):
- pidx1, pidx2 = 1, 0
-
- full_rev=False
- if revision==0: full_rev=True
-
- src=heads.get(branch,'')
- link=''
- if src!='':
- # if we have a cached head, this is an incremental import: initialize it
- # and kill reference so we won't init it again
- wr('from %s' % src)
- heads[branch]=''
- sys.stderr.write('%s: Initializing to parent [%s]\n' %
- (branch,src))
- link=src # avoid making a merge commit for incremental import
- elif link=='' and not heads.has_key(branch) and revision>0:
- if parents[0]>=0:
- # newly created branch with parent: connect to parent
- tmp=get_parent_mark(parents[0],marks)
- wr('from %s' % tmp)
- sys.stderr.write('%s: Link new branch to parent [%s]\n' %
- (branch,tmp))
- link=tmp # avoid making a merge commit for branch fork
- else:
- # newly created branch without parent: feed full revision
- full_rev=True
- elif last.get(branch,revision) != parents[pidx1] and parents[pidx1] > 0 and revision > 0:
- pm=get_parent_mark(parents[pidx1],marks)
- sys.stderr.write('%s: Placing commit [r%d] in branch [%s] on top of [r%d]\n' %
- (branch,revision,branch,parents[pidx1]));
- wr('from %s' % pm)
-
- if parents[pidx2] > 0:
- pm=get_parent_mark(parents[pidx2],marks)
- sys.stderr.write('%s: Merging with parent [%s] from [r%d]\n' %
- (branch,pm,parents[pidx2]))
- wr('merge %s' % pm)
-
- last[branch]=revision
- heads[branch]=''
- # we need this later to write out tags
- marks[str(revision)]=':%d'%(revision+1)
+ parents = [p for p in repo.changelog.parentrevs(revision) if p >= 0]
+
+ # Sort the parents based on revision ids so that we always get the
+ # same resulting git repo, no matter how the revisions were
+ # numbered.
+ parents.sort(key=repo.changelog.node, reverse=True)