# HG changeset patch # User Idan Kamara # Date 1357276289 -3600 # Node ID 767d1c602c8bcee7abbf36a44c4c06a5127f5a83 # Parent c565761dde6aa1a70b688cd2eebad69e9b5a16db 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 -r c565761dde6a -r 767d1c602c8b mercurial/phases.py --- a/mercurial/phases.py Fri Jan 04 01:37:38 2013 +0100 +++ b/mercurial/phases.py Fri Jan 04 06:11:29 2013 +0100 @@ -109,24 +109,6 @@ 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 @@ -156,8 +138,6 @@ 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): @@ -165,8 +145,9 @@ if _load: # Cheap trick to allow shallow-copy without copy module self.phaseroots, self.dirty = _readroots(repo, phasedefaults) + self._phaserevs = None + self.filterunknown(repo) self.opener = repo.sopener - self._phaserevs = None def copy(self): # Shallow copy meant to ensure isolation in @@ -267,6 +248,26 @@ 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.