[PATCH 5 of 5] push: add bookmarks to the unified bundle2 push

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Aug 18 18:48:03 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1408154622 25200
#      Fri Aug 15 19:03:42 2014 -0700
# Node ID e814ea2950f70af18dba3f69e15aece2d39f4814
# Parent  09758826d5987cad7134be10f64a909abe407eec
push: add bookmarks to the unified bundle2 push

We use the `pushkey` part to exchange bookmark updates within the unified
bundle2 push. Note that this only apply on update (move a bookmark known on both
side) since bookmark export (creation of a new bookmark on remote) are apparently
done outside of the _push function.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -420,10 +420,44 @@ def _pushb2phases(pushop, bundler):
                 msg = _('updating %s to public failed!\n') % node
             if msg is not None:
                 pushop.ui.warn(msg)
     return handlereply
 
+ at b2partsgenerator('bookmarks')
+def _pushb2bookmarks(pushop, bundler):
+    """handle phase push through bundle2"""
+    if 'bookmarks' in pushop.stepsdone:
+        return
+    b2caps = bundle2.bundle2caps(pushop.remote)
+    if 'b2x:pushkey' not in b2caps:
+        return
+    pushop.stepsdone.add('bookmarks')
+    part2book = []
+    enc = pushkey.encode
+    for book, old, new in pushop.outbookmarks:
+        part = bundler.newpart('b2x:pushkey')
+        part.addparam('namespace', enc('bookmarks'))
+        part.addparam('key', enc(book))
+        part.addparam('old', enc(old))
+        part.addparam('new', enc(new))
+        part2book.append((part.id, book))
+    def handlereply(op):
+        for partid, book in part2book:
+            partrep = op.records.getreplies(partid)
+            results = partrep['pushkey']
+            assert len(results) <= 1
+            if not results:
+                pushop.ui.warn(_('server ignored bookmark %s update\n') % book)
+            else:
+                ret = int(results[0]['return'])
+                if ret:
+                    pushop.ui.status(_("updating bookmark %s\n") % book)
+                else:
+                    pushop.ui.warn(_('updating bookmark %s failed!\n') % book)
+    return handlereply
+
+
 def _pushbundle2(pushop):
     """push data to the remote using bundle2
 
     The only currently supported type of data is changegroup but this will
     evolve in the future."""


More information about the Mercurial-devel mailing list