[PATCH 3 of 6 phases exchange V2] phases: add basic pushkey support

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Thu Dec 15 05:05:48 CST 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1323944666 -3600
# Node ID f1a13423d9c1e10a28104aeed157e8b5d0b025a2
# Parent  9de2e49957ddfb3b0f41fd4c726e63d779b6129e
phases: add basic pushkey support

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -98,5 +98,49 @@ def retractboundary(repo, targetphase, n
         currentroots.intersection_update(ctx.node() for ctx in ctxs)
         if '_phaserev' in vars(repo):
             del repo._phaserev
         repo._dirtyphases = True
 
+
+def listphases(repo):
+    """List phases root for serialisation over pushkey"""
+    keys = {}
+    for phase in trackedphases:
+        for root in repo._phaseroots[phase]:
+            keys[hex(root)] = '%i' % phase
+    if repo.ui.configbool('phases', 'publish', True):
+        # 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
+        #
+        # We are using nullid for this as nullid is never be used as phase
+        # root.  having a nullid entry in phase roots mean you are a publishing
+        # repo.
+        #
+        # Push do not only push changeset. It also push phase data. New
+        # phase data may apply to common changeset which won't be push (as they
+        # are common).  Here is a very simple example:
+        #
+        # 1) repo A push changeset X as draft to repo B
+        # 2) repo B make changeset X public
+        # 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 pushphase(repo, nhex, oldphasestr, newphasestr):
+    """List phases root for serialisation over pushkey"""
+    lock = repo.lock()
+    try:
+        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:
+            advanceboundary(repo, newphase, [bin(nhex)])
+            return 1
+        else:
+            return 0
+    finally:
+        lock.release()
diff --git a/mercurial/pushkey.py b/mercurial/pushkey.py
--- a/mercurial/pushkey.py
+++ b/mercurial/pushkey.py
@@ -3,20 +3,22 @@
 # Copyright 2010 Matt Mackall <mpm at selenic.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import bookmarks
+import bookmarks, phases
 
 def _nslist(repo):
     n = {}
     for k in _namespaces:
         n[k] = ""
     return n
 
 _namespaces = {"namespaces": (lambda *x: False, _nslist),
-               "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks)}
+               "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks),
+               "phases": (phases.pushphase, phases.listphases),
+              }
 
 def register(namespace, pushkey, listkeys):
     _namespaces[namespace] = (pushkey, listkeys)
 
 def _get(namespace):
diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -32,10 +32,11 @@ import bookmark by name
   (run 'hg update' to get a working copy)
   $ hg bookmarks
      Y                         0:4e3505fd9583
   $ hg debugpushkey ../a namespaces
   bookmarks	
+  phases	
   namespaces	
   $ hg debugpushkey ../a bookmarks
   Y	4e3505fd95835d721066b76e75dbb8cc554d7f77
   X	4e3505fd95835d721066b76e75dbb8cc554d7f77
   Z	4e3505fd95835d721066b76e75dbb8cc554d7f77
@@ -149,10 +150,11 @@ hgweb
   $ cat ../hg.pid >> $DAEMON_PIDS
   $ cd ../a
 
   $ hg debugpushkey http://localhost:$HGPORT/ namespaces 
   bookmarks	
+  phases	
   namespaces	
   $ hg debugpushkey http://localhost:$HGPORT/ bookmarks
   Y	4e3505fd95835d721066b76e75dbb8cc554d7f77
   X	9b140be1080824d768c5a4691a564088eede71f9
   foo	0000000000000000000000000000000000000000
diff --git a/tests/test-ssh.t b/tests/test-ssh.t
--- a/tests/test-ssh.t
+++ b/tests/test-ssh.t
@@ -163,10 +163,11 @@ check remote tip
 test pushkeys and bookmarks
 
   $ cd ../local
   $ hg debugpushkey --config ui.ssh="python $TESTDIR/dummyssh" ssh://user@dummy/remote namespaces
   bookmarks	
+  phases	
   namespaces	
   $ hg book foo -r 0
   $ hg out -B
   comparing with ssh://user@dummy/remote
   searching for changed bookmarks


More information about the Mercurial-devel mailing list