diff mercurial/phases.py @ 16535:39d1f83eb05d stable

branchmap: server should not advertise secret changeset in branchmap (Issue3303) Discovery now use an overlay above branchmap to prune invisible "secret" changeset from branchmap. To minimise impact on the code during the code freeze, this is achieve by recomputing non-secret heads on the fly when any secret changeset exists. This is a computation heavy approach similar to the one used for visible heads. But few sever should contains secret changeset anyway. See comment in code for more robust approach. On local repo the wrapper is applied explicitly while the wire-protocol take care of wrapping branchmap call in a transparent way. This could be unified by the Peter Arrenbrecht and Sune Foldager proposal of a `peer` object. An inappropriate `(+i heads)` may still appear when pushing new changes on a repository with secret changeset. (see Issue3394 for details)
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Tue, 24 Apr 2012 16:32:44 +0200
parents bc1d949261c4
children 72319bfd7966
line wrap: on
line diff
--- a/mercurial/phases.py	Fri Apr 27 13:18:09 2012 -0500
+++ b/mercurial/phases.py	Tue Apr 24 16:32:44 2012 +0200
@@ -263,6 +263,28 @@
         vheads = repo.heads()
     return vheads
 
+def visiblebranchmap(repo):
+    """return a branchmap for the visible set"""
+    # XXX Recomputing this data on the fly is very slow.  We should build a
+    # XXX cached version while computin the standard branchmap version.
+    sroots = repo._phaseroots[secret]
+    if sroots:
+        vbranchmap = {}
+        for branch, nodes in  repo.branchmap().iteritems():
+            # search for secret heads.
+            for n in nodes:
+                if repo[n].phase() >= secret:
+                    nodes = None
+                    break
+            # if secreat heads where found we must compute them again
+            if nodes is None:
+                s = repo.set('heads(branch(%s) - secret())', branch)
+                nodes = [c.node() for c in s]
+            vbranchmap[branch] = nodes
+    else:
+        vbranchmap = repo.branchmap()
+    return vbranchmap
+
 def analyzeremotephases(repo, subset, roots):
     """Compute phases heads and root in a subset of node from root dict