comparison mercurial/bundle2.py @ 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 35095f332846
children b8bd97085ec9
comparison
equal deleted inserted replaced
21659:a319842539f5 21660:e87d2a12d41b
866 def handlelistkeys(op, inpart): 866 def handlelistkeys(op, inpart):
867 """retrieve pushkey namespace content stored in a bundle2""" 867 """retrieve pushkey namespace content stored in a bundle2"""
868 namespace = inpart.params['namespace'] 868 namespace = inpart.params['namespace']
869 r = pushkey.decodekeys(inpart.read()) 869 r = pushkey.decodekeys(inpart.read())
870 op.records.add('listkeys', (namespace, r)) 870 op.records.add('listkeys', (namespace, r))
871
872 @parthandler('b2x:pushkey', ('namespace', 'key', 'old', 'new'))
873 def handlepushkey(op, inpart):
874 """process a pushkey request"""
875 dec = pushkey.decode
876 namespace = dec(inpart.params['namespace'])
877 key = dec(inpart.params['key'])
878 old = dec(inpart.params['old'])
879 new = dec(inpart.params['new'])
880 ret = op.repo.pushkey(namespace, key, old, new)
881 record = {'namespace': namespace,
882 'key': key,
883 'old': old,
884 'new': new}
885 op.records.add('pushkey', record)
886 if op.reply is not None:
887 rpart = op.reply.newpart('b2x:reply:pushkey')
888 rpart.addparam('in-reply-to', str(inpart.id), mandatory=False)
889 rpart.addparam('return', '%i' % ret, mandatory=False)
890
891 @parthandler('b2x:reply:pushkey', ('return', 'in-reply-to'))
892 def handlepushkeyreply(op, inpart):
893 """retrieve the result of a pushkey request"""
894 ret = int(inpart.params['return'])
895 partid = int(inpart.params['in-reply-to'])
896 op.records.add('pushkey', {'return': ret}, partid)