comparison mercurial/wireproto.py @ 37537:be5d4749edc0

wireproto: port pushkey command to wire protocol version 2 It doesn't do output redirection yet. And I'd love to generally overhaul the pushkey protocol for wire protocol version 2. But this will be a bit of effort. Let's do it as a follow-up. Differential Revision: https://phab.mercurial-scm.org/D3204
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 06 Apr 2018 17:39:40 -0700
parents 2003da12f49b
children 89fed81bbb6c
comparison
equal deleted inserted replaced
37536:2003da12f49b 37537:be5d4749edc0
1143 def protocaps(repo, proto, caps): 1143 def protocaps(repo, proto, caps):
1144 if proto.name == wireprototypes.SSHV1: 1144 if proto.name == wireprototypes.SSHV1:
1145 proto._protocaps = set(caps.split(' ')) 1145 proto._protocaps = set(caps.split(' '))
1146 return wireprototypes.bytesresponse('OK') 1146 return wireprototypes.bytesresponse('OK')
1147 1147
1148 @wireprotocommand('pushkey', 'namespace key old new', permission='push') 1148 @wireprotocommand('pushkey', 'namespace key old new', permission='push',
1149 transportpolicy=POLICY_V1_ONLY)
1149 def pushkey(repo, proto, namespace, key, old, new): 1150 def pushkey(repo, proto, namespace, key, old, new):
1150 # compatibility with pre-1.8 clients which were accidentally 1151 # compatibility with pre-1.8 clients which were accidentally
1151 # sending raw binary nodes rather than utf-8-encoded hex 1152 # sending raw binary nodes rather than utf-8-encoded hex
1152 if len(new) == 20 and stringutil.escapestr(new) != new: 1153 if len(new) == 20 and stringutil.escapestr(new) != new:
1153 # looks like it could be a binary node 1154 # looks like it could be a binary node
1374 keys = repo.listkeys(encoding.tolocal(namespace)) 1375 keys = repo.listkeys(encoding.tolocal(namespace))
1375 keys = {encoding.fromlocal(k): encoding.fromlocal(v) 1376 keys = {encoding.fromlocal(k): encoding.fromlocal(v)
1376 for k, v in keys.iteritems()} 1377 for k, v in keys.iteritems()}
1377 1378
1378 return wireprototypes.cborresponse(keys) 1379 return wireprototypes.cborresponse(keys)
1380
1381 @wireprotocommand('pushkey',
1382 args={
1383 'namespace': b'ns',
1384 'key': b'key',
1385 'old': b'old',
1386 'new': b'new',
1387 },
1388 permission='push',
1389 transportpolicy=POLICY_V2_ONLY)
1390 def pushkeyv2(repo, proto, namespace, key, old, new):
1391 # TODO handle ui output redirection
1392 r = repo.pushkey(encoding.tolocal(namespace),
1393 encoding.tolocal(key),
1394 encoding.tolocal(old),
1395 encoding.tolocal(new))
1396
1397 return wireprototypes.cborresponse(r)