changeset 22242:ed222ebd61be

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 applies on update (moving a bookmark known on both sides) since bookmark export (creation of a new bookmark on remote) is apparently done outside of the _push function.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 15 Aug 2014 19:03:42 -0700
parents 3dc3cf8d0e73
children 728669a41947
files mercurial/exchange.py
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/exchange.py	Fri Aug 15 19:03:33 2014 -0700
+++ b/mercurial/exchange.py	Fri Aug 15 19:03:42 2014 -0700
@@ -422,6 +422,40 @@
                 pushop.ui.warn(msg)
     return handlereply
 
+@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