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

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 14, 2016, 9:10 p.m.
Message ID <cab15fd54ee60cc06792.1471209002@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16281/
State Changes Requested
Headers show

Comments

Gregory Szorc - Aug. 14, 2016, 9:10 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@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.
Yuya Nishihara - Aug. 16, 2016, 1:59 p.m.
On Sun, 14 Aug 2016 14:10:02 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@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

> --- 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

I slightly prefer a specially-crafted key over "publishing" string in binary
format, that will never ever conflicts with any possible hash values. (even
I know sha1(x) != "publishing" is guaranteed.)

Patch

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: