repo: move visibleheads and visiblebranchmap logic in discovery
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.
--- a/mercurial/discovery.py Tue Jul 17 01:04:45 2012 +0200
+++ b/mercurial/discovery.py Tue Jul 17 01:22:31 2012 +0200
@@ -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 = visibleheads(repo)
og.excluded = [ctx.node() for ctx in repo.set('secret()')]
else:
# compute common, missing and exclude secret stuff
@@ -261,3 +261,41 @@
# 6. Check for unsynced changes on involved branches.
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:
+ # 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[phases.secret]
+ if sroots:
+ 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 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
+
--- a/mercurial/localrepo.py Tue Jul 17 01:04:45 2012 +0200
+++ b/mercurial/localrepo.py Tue Jul 17 01:22:31 2012 +0200
@@ -56,10 +56,10 @@
return self._repo.lookup(key)
def branchmap(self):
- return phases.visiblebranchmap(self._repo)
+ return discovery.visiblebranchmap(self._repo)
def heads(self):
- return phases.visibleheads(self._repo)
+ return discovery.visibleheads(self._repo)
def known(self, nodes):
return self._repo.known(nodes)
--- a/mercurial/phases.py Tue Jul 17 01:04:45 2012 +0200
+++ b/mercurial/phases.py Tue Jul 17 01:22:31 2012 +0200
@@ -329,43 +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
--- a/mercurial/wireproto.py Tue Jul 17 01:04:45 2012 +0200
+++ b/mercurial/wireproto.py Tue Jul 17 01:22:31 2012 +0200
@@ -10,7 +10,7 @@
from node import bin, hex
import changegroup as changegroupmod
import peer, error, encoding, util, store
-import phases
+import discovery, phases
# abstract batching support
@@ -397,7 +397,7 @@
return "".join(r)
def branchmap(repo, proto):
- branchmap = phases.visiblebranchmap(repo)
+ branchmap = discovery.visiblebranchmap(repo)
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 = discovery.visibleheads(repo)
return encodelist(h) + "\n"
def hello(repo, proto):
@@ -556,7 +556,7 @@
their_heads = decodelist(heads)
def check_heads():
- heads = phases.visibleheads(repo)
+ heads = discovery.visibleheads(repo)
heads_hash = util.sha1(''.join(sorted(heads))).digest()
return (their_heads == ['force'] or their_heads == heads or
their_heads == ['hashed', heads_hash])