[PATCH 3 of 9 RFC] phases: add a binary version of listphases

Gregory Szorc gregory.szorc at gmail.com
Sun Aug 14 17:10:02 EDT 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1471204404 25200
#      Sun Aug 14 12:53:24 2016 -0700
# Node ID cab15fd54ee60cc067920454544586cc4aa03d8e
# Parent  d06d34dd880f58ecef32d96baec16508497d5639
phases: add a binary version of listphases

More preparation for adding a binary listkeys wire protocol command.

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -369,22 +369,28 @@ def retractboundary(repo, tr, targetphas
     This function move boundary *backward* this means that all nodes
     are set in the target phase or kept in a *higher* phase.
 
     Simplify boundary to contains phase roots only."""
     phcache = repo._phasecache.copy()
     phcache.retractboundary(repo, tr, targetphase, nodes)
     repo._phasecache.replace(phcache)
 
-def listphases(repo):
-    """List phases root for serialization over pushkey"""
+def listphasesraw(repo):
+    """Obtain phases pushkey keys.
+
+    Keys are raw binary nodes. Values are '1' to indicate a draft root.
+
+    The special key ``publishing`` with value of ``True`` indicates that the
+    repo is publishing.
+    """
     keys = {}
     value = '%i' % draft
     for root in repo._phasecache.phaseroots[draft]:
-        keys[hex(root)] = value
+        keys[root] = value
 
     if repo.publishing():
         # Add an extra data to let remote know we are a publishing
         # repo. Publishing repo can't just pretend they are old repo.
         # When pushing to a publishing repo, the client still need to
         # push phase boundary
         #
         # Push do not only push changeset. It also push phase data.
@@ -396,16 +402,26 @@ def listphases(repo):
         # 3) repo B push to repo A. X is not pushed but the data that
         #    X as now public should
         #
         # The server can't handle it on it's own as it has no idea of
         # client phase data.
         keys['publishing'] = 'True'
     return keys
 
+def listphases(repo):
+    """List phases root for serialization over pushkey"""
+    d = {}
+    for k, v in listphasesraw(repo).iteritems():
+        if k != 'publishing':
+            k = hex(k)
+        d[k] = v
+
+    return d
+
 def pushphase(repo, nhex, oldphasestr, newphasestr):
     """List phases root for serialization over pushkey"""
     repo = repo.unfiltered()
     with repo.lock():
         currentphase = repo[nhex].phase()
         newphase = abs(int(newphasestr)) # let's avoid negative index surprise
         oldphase = abs(int(oldphasestr)) # let's avoid negative index surprise
         if currentphase == oldphase and newphase < oldphase:


More information about the Mercurial-devel mailing list