mercurial/phases.py
changeset 15456 abcaaf51d568
parent 15454 5a7dde5adec8
child 15480 7d4f364c980b
--- a/mercurial/phases.py	Mon Nov 07 12:27:25 2011 +0100
+++ b/mercurial/phases.py	Mon Nov 07 13:20:22 2011 +0100
@@ -8,7 +8,8 @@
 # GNU General Public License version 2 or any later version.
 
 import errno
-from node import nullid, bin, hex
+from node import nullid, bin, hex, short
+from i18n import _
 
 allphases = range(2)
 trackedphases = allphases[1:]
@@ -41,6 +42,22 @@
     finally:
         f.close()
 
+def filterunknown(repo, phaseroots=None):
+    """remove unknown nodes from the phase boundary
+
+    no data is lost as unknown node only old data for their descentants
+    """
+    if phaseroots is None:
+        phaseroots = repo._phaseroots
+    for phase, nodes in enumerate(phaseroots):
+        missing = [node for node in nodes if node not in repo]
+        if missing:
+            for mnode in missing:
+                msg = _('Removing unknown node %(n)s from %(p)i-phase boundary')
+                repo.ui.debug(msg, {'n': short(mnode), 'p': phase})
+            nodes.symmetric_difference_update(missing)
+            repo._dirtyphases = True
+
 def moveboundary(repo, target_phase, nodes):
     """Add nodes to a phase changing other nodes phases if necessary.