mirror of
https://github.com/mnauw/git-remote-hg.git
synced 2026-07-14 19:51:27 +02:00
remote-hg: make sure we omit multiple heads
We want to ignore secondary heads, otherwise we will import revisions that won't have any ref pointing to them and might eventually be pruned, which would cause problems with the synchronization of marks. This can only be expressed properly as '::b - ::a', but that's not efficient, specially in older versions of Mercurial. 'ancestor(a,b)::b - ancestor(a,b)::a' might be better, but it's not particularly pretty. Mercurial v3.0 will have a new 'only(b, a)' that does the same, but that hasn't even been released yet. Either way all of these require repo.revs() which is only available after Mercurial v2.1. Also, we would need special considerations for when there's no base revision (importing from root). It's much better to implement our own function to get a range of revisions. The new gitrange() is inspired by Mercurial's revset.missingancestors(). Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
This commit is contained in:
@@ -437,16 +437,46 @@ def rev_to_mark(rev):
|
||||
def mark_to_rev(mark):
|
||||
return marks.to_rev(mark)
|
||||
|
||||
# Get a range of revisions in the form of a..b (git committish)
|
||||
def gitrange(repo, a, b):
|
||||
positive = []
|
||||
pending = set([int(b)])
|
||||
negative = set([int(a)])
|
||||
for cur in xrange(b, -1, -1):
|
||||
if not pending:
|
||||
break
|
||||
|
||||
parents = [p for p in repo.changelog.parentrevs(cur) if p >= 0]
|
||||
|
||||
if cur in pending:
|
||||
positive.append(cur)
|
||||
pending.remove(cur)
|
||||
for p in parents:
|
||||
if not p in negative:
|
||||
pending.add(p)
|
||||
elif cur in negative:
|
||||
negative.remove(cur)
|
||||
for p in parents:
|
||||
if not p in pending:
|
||||
negative.add(p)
|
||||
else:
|
||||
pending.discard(p)
|
||||
|
||||
positive.reverse()
|
||||
return positive
|
||||
|
||||
def export_ref(repo, name, kind, head):
|
||||
ename = '%s/%s' % (kind, name)
|
||||
try:
|
||||
tip = marks.get_tip(ename)
|
||||
tip = repo[tip].rev()
|
||||
tip = repo[tip]
|
||||
except:
|
||||
tip = 0
|
||||
tip = repo[-1]
|
||||
|
||||
revs = gitrange(repo, tip, head)
|
||||
|
||||
revs = xrange(tip, head.rev() + 1)
|
||||
total = len(revs)
|
||||
tip = tip.rev()
|
||||
|
||||
for rev in revs:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user