phases: add a function to compute heads from root
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Thu, 15 Dec 2011 02:18:24 +0100
changeset 15649 ca7c4254a21a
parent 15648 79cc89de5be1
child 15650 5b26667fc4d3
phases: add a function to compute heads from root
mercurial/phases.py
--- a/mercurial/phases.py	Thu Dec 15 11:24:26 2011 +0100
+++ b/mercurial/phases.py	Thu Dec 15 02:18:24 2011 +0100
@@ -140,3 +140,30 @@
             return 0
     finally:
         lock.release()
+
+def analyzeremotephases(repo, subset, roots):
+    """Compute phases heads and root in a subset of node from root dict
+
+    * subset is heads of the subset
+    * roots is {<nodeid> => phase} mapping. key and value are string.
+
+    Accept unknown element input
+    """
+    # build list from dictionary
+    phaseroots = [[] for p in allphases]
+    for nhex, phase in roots.iteritems():
+        if nhex == 'publishing': # ignore data related to publish option
+            continue
+        node = bin(nhex)
+        phase = int(phase)
+        if node in repo:
+            phaseroots[phase].append(node)
+    # compute heads
+    phaseheads = [[] for p in allphases]
+    for phase in allphases[:-1]:
+        toproof = phaseroots[phase + 1]
+        revset = repo.set('heads((%ln + parents(%ln)) - (%ln::%ln))',
+                          subset, toproof, toproof, subset)
+        phaseheads[phase].extend(c.node() for c in revset)
+    return phaseheads, phaseroots
+