[PATCH V2] discovery: simplify branchmap construction against legacy server

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Fri Jun 22 05:31:37 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1340360269 -7200
# Node ID 45f0feeb42d14aa21aba233bf598707232b24782
# Parent  efd2e14f72353626355dc82465bdf23bf6416aa2
discovery: simplify branchmap construction against legacy server

All necessary data to fire a simple revset query are already known. No call to
ancestors are needed. Such ancestors calculation was already done to compute
outgoing.missing.

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -205,22 +205,20 @@ def checkheads(repo, remote, outgoing, r
 
     else:
         # 1-4b. old servers: Check for new topological heads.
         # Construct {old,new}map with branch = None (topological branch).
         # (code based on _updatebranchcache)
-        oldheadrevs = set(cl.rev(h) for h in remoteheads if h in cl.nodemap)
-        missingrevs = [cl.rev(node) for node in outgoing.missing]
-        newheadrevs = oldheadrevs.union(missingrevs)
-        if len(newheadrevs) > 1:
-            for latest in sorted(missingrevs, reverse=True):
-                if latest not in newheadrevs:
-                    continue
-                reachable = cl.ancestors([latest], min(newheadrevs))
-                newheadrevs.difference_update(reachable)
+        oldheads = set(h for h in remoteheads if h in cl.nodemap)
+        # all nodes in outgoing.missing are children of either:
+        # - an element of oldheads
+        # - another element of outgoing.missing
+        # - nullrev
+        # This explains why the new head are very simple to compute.
+        r = repo.set('heads(%ln + %ln)', oldheads, outgoing.missing)
         branches = set([None])
-        newmap = {None: [cl.node(rev) for rev in newheadrevs]}
-        oldmap = {None: [cl.node(rev) for rev in oldheadrevs]}
+        newmap = {None: list(c.node() for c in r)}
+        oldmap = {None: oldheads}
         unsynced = inc and branches or set()
 
     # 5. Check for new heads.
     # If there are more heads after the push than before, a suitable
     # error message, depending on unsynced status, is displayed.


More information about the Mercurial-devel mailing list