[PATCH 07 of 16] phases: make _filterunknown a member function of phasecache
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Tue Jan 1 19:09:29 CST 2013
# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1355682488 -7200
# Node ID 223cb873a170ee0d9c6a9d3ec93aeb8057ca4ffe
# Parent 42d39c8232de6b32d6e489329bf10656960ae8a7
phases: make _filterunknown a member function of phasecache
We'd like the ability to call filterunknown on an existing phasecache
instance after nodes are destroyed.
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -107,28 +107,10 @@ import util, error
allphases = public, draft, secret = range(3)
trackedphases = allphases[1:]
phasenames = ['public', 'draft', 'secret']
-def _filterunknown(ui, changelog, phaseroots):
- """remove unknown nodes from the phase boundary
-
- Nothing is lost as unknown nodes only hold data for their descendants.
- """
- updated = False
- nodemap = changelog.nodemap # to filter unknown nodes
- for phase, nodes in enumerate(phaseroots):
- missing = [node for node in nodes if node not in nodemap]
- if missing:
- for mnode in missing:
- ui.debug(
- 'removing unknown node %s from %i-phase boundary\n'
- % (short(mnode), phase))
- nodes.symmetric_difference_update(missing)
- updated = True
- return updated
-
def _readroots(repo, phasedefaults=None):
"""Read phase roots from disk
phasedefaults is a list of fn(repo, roots) callable, which are
executed if the phase roots file does not exist. When phases are
@@ -154,19 +136,18 @@ def _readroots(repo, phasedefaults=None)
raise
if phasedefaults:
for f in phasedefaults:
roots = f(repo, roots)
dirty = True
- if _filterunknown(repo.ui, repo.changelog, roots):
- dirty = True
return roots, dirty
class phasecache(object):
def __init__(self, repo, phasedefaults, _load=True):
if _load:
# Cheap trick to allow shallow-copy without copy module
self.phaseroots, self.dirty = _readroots(repo, phasedefaults)
+ self.filterunknown(repo)
self.opener = repo.sopener
self._phaserevs = None
def copy(self):
# Shallow copy meant to ensure isolation in
@@ -265,10 +246,30 @@ class phasecache(object):
ctxs = repo.set('roots(%ln::)', currentroots)
currentroots.intersection_update(ctx.node() for ctx in ctxs)
self._updateroots(targetphase, currentroots)
repo.invalidatevolatilesets()
+ def filterunknown(self, repo):
+ """remove unknown nodes from the phase boundary
+
+ Nothing is lost as unknown nodes only hold data for their descendants.
+ """
+ filtered = False
+ nodemap = repo.changelog.nodemap # to filter unknown nodes
+ for phase, nodes in enumerate(self.phaseroots):
+ missing = [node for node in nodes if node not in nodemap]
+ if missing:
+ for mnode in missing:
+ repo.ui.debug(
+ 'removing unknown node %s from %i-phase boundary\n'
+ % (short(mnode), phase))
+ nodes.symmetric_difference_update(missing)
+ filtered = True
+ if filtered:
+ self.dirty = True
+ self._phaserevs = None
+
def advanceboundary(repo, targetphase, nodes):
"""Add nodes to a phase changing other nodes phases if necessary.
This function move boundary *forward* this means that all nodes
are set in the target phase or kept in a *lower* phase.
More information about the Mercurial-devel
mailing list