[PATCH 7 of 8] repo: move visibleheads and visiblebranchmap logic on repo

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Jul 5 19:27:29 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1341532735 -7200
# Node ID edbb77b7fb7832d00e41059618a69b9fb9e7eb82
# Parent  d3e62e93711233bf43fee5ce2ea9e6cf2efccd4c
repo: move visibleheads and visiblebranchmap logic on repo.

They were previously inside the mercurial.phases module, but obsolete logic will
need them to exclude `extinct` changesets from pull and push.

The proper and planned way to implement such filtering is still to apply a
changelog level filtering. But we are far to late in the cycle to implement and
push such a critical piece of code (changelog filtering). With Matt Mackall
approval I'm extending this quick and dirty mechanism for obsolete purpose.

Changelog level filtering should come during the next release cycle.

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -113,7 +113,7 @@
         og.missingheads = onlyheads or repo.heads()
     elif onlyheads is None:
         # use visible heads as it should be cached
-        og.missingheads = phases.visibleheads(repo)
+        og.missingheads = repo.visibleheads()
         og.excluded = [ctx.node() for ctx in repo.set('secret()')]
     else:
         # compute common, missing and exclude secret stuff
@@ -169,7 +169,7 @@
 
         # 2. Check for new branches on the remote.
         if remote.local():
-            remotemap = phases.visiblebranchmap(remote)
+            remotemap = remote.visiblebranchmap()
         else:
             remotemap = remote.branchmap()
         newbranches = branches - set(remotemap)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -514,6 +514,28 @@
         self.updatebranchcache()
         return self._branchcache
 
+    def visiblebranchmap(self):
+        """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 = self._phasecache.phaseroots[phases.secret]
+        if sroots:
+            vbranchmap = {}
+            for branch, nodes in  self.branchmap().iteritems():
+                # search for secret heads.
+                for n in nodes:
+                    if self[n].phase() >= phases.secret:
+                        nodes = None
+                        break
+                # if secreat heads where found we must compute them again
+                if nodes is None:
+                    s = self.set('heads(branch(%s) - secret())', branch)
+                    nodes = [c.node() for c in s]
+                vbranchmap[branch] = nodes
+        else:
+            vbranchmap = self.branchmap()
+        return vbranchmap
+
     def _branchtip(self, heads):
         '''return the tipmost branch head in heads'''
         tip = heads[-1]
@@ -1561,6 +1583,22 @@
         # sort the output in rev descending order
         return sorted(heads, key=self.changelog.rev, reverse=True)
 
+    def visibleheads(self):
+        """return the set of visible head of this self"""
+        # XXX we want a cache on this
+        sroots = self._phasecache.phaseroots[phases.secret]
+        if sroots:
+            # XXX very slow revset. storing heads or secret "boundary"
+            # would help.
+            revset = self.set('heads(not (%ln::))', sroots)
+
+            vheads = [ctx.node() for ctx in revset]
+            if not vheads:
+                vheads.append(nullid)
+        else:
+            vheads = self.heads()
+        return vheads
+
     def branchheads(self, branch=None, start=None, closed=False):
         '''return a (possibly filtered) list of heads for the given branch
 
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -329,42 +329,6 @@
     finally:
         lock.release()
 
-def visibleheads(repo):
-    """return the set of visible head of this repo"""
-    # XXX we want a cache on this
-    sroots = repo._phasecache.phaseroots[secret]
-    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 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._phasecache.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
diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py
+++ b/mercurial/setdiscovery.py
@@ -9,7 +9,6 @@
 from node import nullid
 from i18n import _
 import random, util, dagutil
-import phases
 
 def _updatesample(dag, nodes, sample, always, quicksamplesize=0):
     # if nodes is empty we scan the entire graph
@@ -100,7 +99,7 @@
     sample = ownheads
     if remote.local():
         # stopgap until we have a proper localpeer that supports batch()
-        srvheadhashes = phases.visibleheads(remote)
+        srvheadhashes = remote.visibleheads()
         yesno = remote.known(dag.externalizeall(sample))
     elif remote.capable('batch'):
         batch = remote.batch()
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -397,7 +397,7 @@
     return "".join(r)
 
 def branchmap(repo, proto):
-    branchmap = phases.visiblebranchmap(repo)
+    branchmap = repo.visiblebranchmap()
     heads = []
     for branch, nodes in branchmap.iteritems():
         branchname = urllib.quote(encoding.fromlocal(branch))
@@ -453,7 +453,7 @@
     return streamres(proto.groupchunks(cg))
 
 def heads(repo, proto):
-    h = phases.visibleheads(repo)
+    h = repo.visibleheads()
     return encodelist(h) + "\n"
 
 def hello(repo, proto):
@@ -556,7 +556,7 @@
     their_heads = decodelist(heads)
 
     def check_heads():
-        heads = phases.visibleheads(repo)
+        heads = repo.visibleheads()
         heads_hash = util.sha1(''.join(sorted(heads))).digest()
         return (their_heads == ['force'] or their_heads == heads or
                 their_heads == ['hashed', heads_hash])


More information about the Mercurial-devel mailing list