git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/8] remote-hg: make sure we omit multiple heads

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 29, 2014, 09:04 UTC
Message-ID
<1398762275-346-8-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1398762275-346-1-git-send-email-felipe.contreras@gmail.com>

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>
---
 git-remote-hg.py | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/git-remote-hg.py b/git-remote-hg.py
index cd3d79e..402b92f 100755
--- a/git-remote-hg.py
+++ b/git-remote-hg.py
@@ -437,16 +437,45 @@ 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 = xrange(tip, head.rev() + 1)
+    revs = gitrange(repo, tip, head)
     total = len(revs)
+    tip = tip.rev()
 
     for rev in revs:
 
-- 
1.9.2+fc1.3.gade8541
Previous: Felipe ContrerasNext: Felipe Contreras
Message 8 of 10 in “remote-helper: fixes”
  1. 0/8 remote-helper: fixesFelipe Contreras, Apr 29, 2014
  2. 1/8 remote-hg: fix parsing of custom committerFelipe Contreras, Apr 29, 2014
  3. 2/8 remote-hg: update to 'public' phase when pushingFelipe Contreras, Apr 29, 2014
  4. 3/8 remote-{hg,bzr}: store marks only on successFelipe Contreras, Apr 29, 2014
  5. 4/8 remote-hg: properly detect missing contextsFelipe Contreras, Apr 29, 2014
  6. 5/8 t: remote-hg: split into setup testFelipe Contreras, Apr 29, 2014
  7. 6/8 git-remote-hg: use internal clone's hgrcFelipe Contreras, Apr 29, 2014
  8. 7/8 remote-hg: make sure we omit multiple headsFelipe Contreras, Apr 29, 2014
  9. 8/8 remote-hg: trivial cleanupsFelipe Contreras, Apr 29, 2014
  10. Philip OakleyApr 29, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.