changeset 21660:e87d2a12d41b

bundle2: add ``pushkey`` support After ``listkeys`` we can now include ``pushkey`` request in a bundle2. The part uses a very simple scheme closest as possible to the current wireproto command for ``pushkey``. We may eventually decide for a more sophisticated part format before the protocol becomes final.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 27 May 2014 16:32:50 -0700
parents a319842539f5
children 2f52a16f2bee
files mercurial/bundle2.py mercurial/localrepo.py
diffstat 2 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Thu May 29 15:23:25 2014 -0700
+++ b/mercurial/bundle2.py	Tue May 27 16:32:50 2014 -0700
@@ -868,3 +868,29 @@
     namespace = inpart.params['namespace']
     r = pushkey.decodekeys(inpart.read())
     op.records.add('listkeys', (namespace, r))
+
+@parthandler('b2x:pushkey', ('namespace', 'key', 'old', 'new'))
+def handlepushkey(op, inpart):
+    """process a pushkey request"""
+    dec = pushkey.decode
+    namespace = dec(inpart.params['namespace'])
+    key = dec(inpart.params['key'])
+    old = dec(inpart.params['old'])
+    new = dec(inpart.params['new'])
+    ret = op.repo.pushkey(namespace, key, old, new)
+    record = {'namespace': namespace,
+              'key': key,
+              'old': old,
+              'new': new}
+    op.records.add('pushkey', record)
+    if op.reply is not None:
+        rpart = op.reply.newpart('b2x:reply:pushkey')
+        rpart.addparam('in-reply-to', str(inpart.id), mandatory=False)
+        rpart.addparam('return', '%i' % ret, mandatory=False)
+
+@parthandler('b2x:reply:pushkey', ('return', 'in-reply-to'))
+def handlepushkeyreply(op, inpart):
+    """retrieve the result of a pushkey request"""
+    ret = int(inpart.params['return'])
+    partid = int(inpart.params['in-reply-to'])
+    op.records.add('pushkey', {'return': ret}, partid)
--- a/mercurial/localrepo.py	Thu May 29 15:23:25 2014 -0700
+++ b/mercurial/localrepo.py	Tue May 27 16:32:50 2014 -0700
@@ -181,7 +181,8 @@
     filtername = None
 
     bundle2caps = {'HG2X': (),
-                   'b2x:listkeys': ()}
+                   'b2x:listkeys': (),
+                   'b2x:pushkey': ()}
 
     # a list of (ui, featureset) functions.
     # only functions defined in module of enabled extensions are invoked