changeset 18220:767d1c602c8b

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.
author Idan Kamara <idankk86@gmail.com>
date Fri, 04 Jan 2013 06:11:29 +0100
parents c565761dde6a
children 082d6929fd4d
files mercurial/phases.py
diffstat 1 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- 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.