[PATCH 13 of 17 RFC] clfilter: use filtering in `visibleheads` and `visiblebranchmap`

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Mon Sep 3 07:58:37 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1346676788 -7200
# Node ID 2482fac4a05dae3211484df1cbf3ab1340ad30fd
# Parent  c231611a44cef373a4f8da1add8346fa7f368b96
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
@@ -328,42 +328,19 @@ def checkheads(repo, remote, outgoing, r
     if unsynced:
         repo.ui.warn(_("note: unsynced remote changes!\n"))
 
 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
+    refilter = repo.revsfilter.set('unserved')
+    try:
+        return repo.heads()
+    finally:
+        refilter()
 
 
 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
+    refilter = repo.revsfilter.set('unserved')
+    try:
+        return repo.branchmap()
+    finally:
+        refilter()
diff --git a/mercurial/repofilter.py b/mercurial/repofilter.py
--- a/mercurial/repofilter.py
+++ b/mercurial/repofilter.py
@@ -6,11 +6,15 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 import weakref
 
-computefiltered = {}
+def computeunserved(repo):
+    assert not repo.changelog.filteredrevs
+    return set(repo.revs('hidden() + secret()'))
+
+computefiltered = {'unserved': computeunserved}
 
 
 class revsfilter(object):
 
     def __init__(self, repo):


More information about the Mercurial-devel mailing list