[PATCH 5 of 6 phases] phases: add a function to compute visible heads

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Mon Dec 19 04:46:51 CST 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1324291064 -3600
# Node ID 3ae9a35bb323deaf364174340e93d392c2f7c4fd
# Parent  c52a3118d3a95c8b76ea1385ac5da6007aaefbdb
phases: add a function to compute visible heads

This function will be used to hide secret changeset.

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -234,10 +234,25 @@ def pushphase(repo, nhex, oldphasestr, n
         else:
             return 0
     finally:
         lock.release()
 
+def visibleheads(repo):
+    """return the set of visible head of this repo"""
+    # XXX we want a cache on this
+    sroots = repo._phaseroots[2]
+    if sroots:
+        # XXX very slow revset. storing heads or secret "boundary" would help.
+        revset = repo.set('heads(not (%ln::))', sroots)
+
+        vheads = [ctx.node() for ctx in revset]
+        if not vheads:
+            vheads.append(nullid)
+    else:
+        vheads = repo.heads()
+    return vheads
+
 def analyzeremotephases(repo, subset, roots):
     """Compute phases heads and root in a subset of node from root dict
 
     * subset is heads of the subset
     * roots is {<nodeid> => phase} mapping. key and value are string.


More information about the Mercurial-devel mailing list