[PATCH 22 of 27 clfilter V2] clfilter: use filtering in `visibleheads` and `visiblebranchmap`

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Oct 8 16:38:13 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1349354591 -7200
# Node ID 3140953fd3c1403af6a266bd9990b0107aa2715d
# Parent  412d0319e39b958de80d2a25b0218164ef6f8160
clfilter: use filtering in `visibleheads` and `visiblebranchmap`

This is the first real use of changelog filtering. The change is very small to
allow testing the new filter with a setup close to the original one. The two
functions are removed in followup.

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -338,40 +338,9 @@
 
 def visibleheads(repo):
     """return the set of visible head of this repo"""
-    # XXX we want a cache on this
-    sroots = repo._phasecache.phaseroots[phases.secret]
-    if sroots or repo.obsstore:
-        # XXX very slow revset. storing heads or secret "boundary"
-        # would help.
-        revset = repo.set('heads(not (%ln:: + extinct()))', sroots)
-
-        vheads = [ctx.node() for ctx in revset]
-        if not vheads:
-            vheads.append(nullid)
-    else:
-        vheads = repo.heads()
-    return vheads
+    return repo.filtered('unserved').heads()
 
 
 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 computing the standard branchmap version.
-    sroots = repo._phasecache.phaseroots[phases.secret]
-    if sroots or repo.obsstore:
-        vbranchmap = {}
-        for branch, nodes in  repo.branchmap().iteritems():
-            # search for secret heads.
-            for n in nodes:
-                if repo[n].phase() >= phases.secret:
-                    nodes = None
-                    break
-            # if secret heads were found we must compute them again
-            if nodes is None:
-                s = repo.set('heads(branch(%s) - secret() - extinct())',
-                             branch)
-                nodes = [c.node() for c in s]
-            vbranchmap[branch] = nodes
-    else:
-        vbranchmap = repo.branchmap()
-    return vbranchmap
+    return repo.filtered('unserved').branchmap()
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -58,7 +58,14 @@
     return wrapper
 
 # function to compute filtered set
-computefiltered = {}
+def computeunserved(repo):
+    """compute the set of revision that should be filtered when used a server
+
+    Secret and hidden changeset should not pretend to be here."""
+    assert not repo.changelog.filteredrevs
+    return frozenset(repo.revs('hidden() + secret()'))
+
+computefiltered = {'unserved': computeunserved}
 
 def _filteredrevs(repo, filtername):
     """returns set of filtered revision for this filter name"""


More information about the Mercurial-devel mailing list