[PATCH 06 of 12] phases: add a moveboundary function to move phases boundaries

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Tue Oct 18 12:27:03 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1318955262 -7200
# Node ID 568b9dfebb7e9224d5b0f0fe9628f54fb30aca16
# Parent  3c425f06d6bfab5b32e0da230c9fc0a615814ae5
phases: add a moveboundary function to move phases boundaries

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -37,5 +37,34 @@ def writeheads(repo):
             for h in heads:
                 f.write('%i %s\n' % (phase, hex(h)))
     finally:
         f.close()
 
+def moveboundary(repo, phase, nodes):
+    """Add nodes to a phase changing other nodes phases if necessary.
+
+    return True if phase boundary moved, False otherwise.
+
+    Simplify boundary to contains phase head only."""
+    if phase not in trackedphases:
+        return False
+    heads = repo._phaseheads[phase]
+    olds = heads.copy()
+    heads.update(set(nodes))
+    if olds != heads:
+        # remove nullid as it's rev is -1 and it confuse revset
+        if nullid in heads:
+            heads.remove(nullid)
+        # compute heads of the new set
+        revs = map(repo.changelog.rev, heads)
+        ctxs = repo.set('heads(::(%ld))', revs)
+        nodes = set([ctx.node() for ctx in ctxs])
+        heads.intersection_update(nodes)
+        # If heads really changed
+        if olds != heads:
+            # recursively move other phase boundary
+            moveboundary(repo, phase + 1, nodes) # cascading
+            # invalidate cache (we probably could be smarter here
+            if '_phaserev' in vars(repo):
+                del repo._phaserev
+            return True
+    return False


More information about the Mercurial-devel mailing list