Patchwork [4,of,5,filtering,part,2] clfilter: use filtering in `visibleheads` and `visiblebranchmap`

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 4, 2012, 12:26 a.m.
Message ID <cf4c5d45f5049f584202.1354580817@yamac.lan>
Download mbox | patch
Permalink /patch/9/
State Superseded, archived
Commit a2cebd3e4daaa0565733b75fa1275c497746e115
Headers show

Comments

Pierre-Yves David - Dec. 4, 2012, 12:26 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1354463434 -3600
# Node ID cf4c5d45f5049f584202f7af4434b6586201e623
# Parent  6c38bdbce9bcbd96fd23476561f1443c17c18d6f
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.

We replace custom post processing on `heads` and `branchmap` function by call to
the standard code pass on a filtering repo.

In later coming will have wider usage of filtering that will make the dedicated
function useless.

Patch

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -336,42 +336,11 @@  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
+    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
@@ -57,11 +57,21 @@  def unfilteredmethod(orig):
     def wrapper(repo, *args, **kwargs):
         return orig(repo.unfiltered(), *args, **kwargs)
     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
+    # fast path in simple case to avoid impact of non optimised code
+    if phases.hassecret(repo) or repo.obsstore:
+        return frozenset(repo.revs('hidden() + secret()'))
+    return ()
+
+computefiltered = {'unserved': computeunserved}
 
 def _filteredrevs(repo, filtername):
     """returns set of filtered revision for this filter name"""
     if filtername not in repo.revsfiltercache:
         func = computefiltered[filtername]
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -174,10 +174,11 @@  the public changeset
 And that we can't push bumped changeset
 
   $ hg push ../tmpa -r 0 --force #(make repo)
   pushing to ../tmpa
   searching for changes
+  warning: repository is unrelated
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
   $ hg push ../tmpa