Mercurial > public > mercurial-scm > hg
comparison mercurial/wireproto.py @ 37538:89fed81bbb6c
wireproto: port lookup to wire protocol v2
This is pretty straightforward. We don't yet handle errors because we
don't have an error handling mechanism in place yet.
I'm also tempted to fold this into `known`. We'll come back to this
later.
Differential Revision: https://phab.mercurial-scm.org/D3205
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 06 Apr 2018 17:48:07 -0700 |
parents | be5d4749edc0 |
children | 4a0d58d6faba |
comparison
equal
deleted
inserted
replaced
37537:be5d4749edc0 | 37538:89fed81bbb6c |
---|---|
1118 transportpolicy=POLICY_V1_ONLY) | 1118 transportpolicy=POLICY_V1_ONLY) |
1119 def listkeys(repo, proto, namespace): | 1119 def listkeys(repo, proto, namespace): |
1120 d = sorted(repo.listkeys(encoding.tolocal(namespace)).items()) | 1120 d = sorted(repo.listkeys(encoding.tolocal(namespace)).items()) |
1121 return wireprototypes.bytesresponse(pushkeymod.encodekeys(d)) | 1121 return wireprototypes.bytesresponse(pushkeymod.encodekeys(d)) |
1122 | 1122 |
1123 @wireprotocommand('lookup', 'key', permission='pull') | 1123 @wireprotocommand('lookup', 'key', permission='pull', |
1124 transportpolicy=POLICY_V1_ONLY) | |
1124 def lookup(repo, proto, key): | 1125 def lookup(repo, proto, key): |
1125 try: | 1126 try: |
1126 k = encoding.tolocal(key) | 1127 k = encoding.tolocal(key) |
1127 n = repo.lookup(k) | 1128 n = repo.lookup(k) |
1128 r = hex(n) | 1129 r = hex(n) |
1376 keys = {encoding.fromlocal(k): encoding.fromlocal(v) | 1377 keys = {encoding.fromlocal(k): encoding.fromlocal(v) |
1377 for k, v in keys.iteritems()} | 1378 for k, v in keys.iteritems()} |
1378 | 1379 |
1379 return wireprototypes.cborresponse(keys) | 1380 return wireprototypes.cborresponse(keys) |
1380 | 1381 |
1382 @wireprotocommand('lookup', | |
1383 args={ | |
1384 'key': b'foo', | |
1385 }, | |
1386 permission='pull', | |
1387 transportpolicy=POLICY_V2_ONLY) | |
1388 def lookupv2(repo, proto, key): | |
1389 key = encoding.tolocal(key) | |
1390 | |
1391 # TODO handle exception. | |
1392 node = repo.lookup(key) | |
1393 | |
1394 return wireprototypes.cborresponse(node) | |
1395 | |
1381 @wireprotocommand('pushkey', | 1396 @wireprotocommand('pushkey', |
1382 args={ | 1397 args={ |
1383 'namespace': b'ns', | 1398 'namespace': b'ns', |
1384 'key': b'key', | 1399 'key': b'key', |
1385 'old': b'old', | 1400 'old': b'old', |