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:
Felipe Contreras
2014-04-23 15:23:53 -05:00
parent 1c72617831
commit ef00e40d7c

View File

@@ -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: