##// END OF EJS Templates
wireproto: port pushkey command to wire protocol version 2...
Gregory Szorc -
r37555:be5d4749 default
parent child Browse files
Show More
@@ -0,0 +1,89 b''
1 $ . $TESTDIR/wireprotohelpers.sh
2
3 $ hg init server
4 $ enablehttpv2 server
5 $ cd server
6 $ cat >> .hg/hgrc << EOF
7 > [web]
8 > push_ssl = false
9 > allow-push = *
10 > EOF
11 $ hg debugdrawdag << EOF
12 > C D
13 > |/
14 > B
15 > |
16 > A
17 > EOF
18
19 $ hg serve -p $HGPORT -d --pid-file hg.pid -E error.log
20 $ cat hg.pid > $DAEMON_PIDS
21
22 pushkey for a bookmark works
23
24 $ sendhttpv2peer << EOF
25 > command pushkey
26 > namespace bookmarks
27 > key @
28 > old
29 > new 426bada5c67598ca65036d57d9e4b64b0c1ce7a0
30 > EOF
31 creating http peer for wire protocol version 2
32 sending pushkey command
33 s> *\r\n (glob)
34 s> Accept-Encoding: identity\r\n
35 s> accept: application/mercurial-exp-framing-0003\r\n
36 s> content-type: application/mercurial-exp-framing-0003\r\n
37 s> content-length: 105\r\n
38 s> host: $LOCALIP:$HGPORT\r\n (glob)
39 s> user-agent: Mercurial debugwireproto\r\n
40 s> \r\n
41 s> a\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa4CkeyA@CnewX(426bada5c67598ca65036d57d9e4b64b0c1ce7a0Cold@InamespaceIbookmarksDnameGpushkey
42 s> makefile('rb', None)
43 s> HTTP/1.1 200 OK\r\n
44 s> Server: testing stub value\r\n
45 s> Date: $HTTP_DATE$\r\n
46 s> Content-Type: application/mercurial-exp-framing-0003\r\n
47 s> Transfer-Encoding: chunked\r\n
48 s> \r\n
49 s> 9\r\n
50 s> *\x00\x01\x00\x02\x01F (glob)
51 s> \xf5
52 s> \r\n
53 received frame(size=*; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) (glob)
54 s> 0\r\n
55 s> \r\n
56 response: []
57
58 $ sendhttpv2peer << EOF
59 > command listkeys
60 > namespace bookmarks
61 > EOF
62 creating http peer for wire protocol version 2
63 sending listkeys command
64 s> POST /api/exp-http-v2-0001/ro/listkeys HTTP/1.1\r\n
65 s> Accept-Encoding: identity\r\n
66 s> accept: application/mercurial-exp-framing-0003\r\n
67 s> content-type: application/mercurial-exp-framing-0003\r\n
68 s> content-length: 49\r\n
69 s> host: $LOCALIP:$HGPORT\r\n (glob)
70 s> user-agent: Mercurial debugwireproto\r\n
71 s> \r\n
72 s> )\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa1InamespaceIbookmarksDnameHlistkeys
73 s> makefile('rb', None)
74 s> HTTP/1.1 200 OK\r\n
75 s> Server: testing stub value\r\n
76 s> Date: $HTTP_DATE$\r\n
77 s> Content-Type: application/mercurial-exp-framing-0003\r\n
78 s> Transfer-Encoding: chunked\r\n
79 s> \r\n
80 s> 35\r\n
81 s> -\x00\x00\x01\x00\x02\x01F
82 s> \xa1A@X(426bada5c67598ca65036d57d9e4b64b0c1ce7a0
83 s> \r\n
84 received frame(size=45; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor)
85 s> 0\r\n
86 s> \r\n
87 response: [{b'@': b'426bada5c67598ca65036d57d9e4b64b0c1ce7a0'}]
88
89 $ cat error.log
@@ -1777,3 +1777,22 b' namespace'
1777 The response is a map with bytestring keys and values.
1777 The response is a map with bytestring keys and values.
1778
1778
1779 TODO consider using binary to represent nodes in certain pushkey namespaces.
1779 TODO consider using binary to represent nodes in certain pushkey namespaces.
1780
1781 pushkey
1782 -------
1783
1784 Set a value using the ``pushkey`` protocol.
1785
1786 The command receives the following arguments:
1787
1788 namespace
1789 (bytestring) Pushkey namespace to operate on.
1790 key
1791 (bytestring) The pushkey key to set.
1792 old
1793 (bytestring) Old value for this key.
1794 new
1795 (bytestring) New value for this key.
1796
1797 TODO consider using binary to represent nodes is certain pushkey namespaces.
1798 TODO better define response type and meaning.
@@ -1145,7 +1145,8 b' def protocaps(repo, proto, caps):'
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
@@ -1376,3 +1377,21 b' def listkeysv2(repo, proto, namespace=No'
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)
@@ -30,11 +30,11 b' capabilities request returns an array of'
30 s> \r\n
30 s> \r\n
31 s> *\r\n (glob)
31 s> *\r\n (glob)
32 s> *\x00\x01\x00\x02\x01F (glob)
32 s> *\x00\x01\x00\x02\x01F (glob)
33 s> \xa2Hcommands\xa9Eheads\xa2Dargs\xa1Jpubliconly\xf4Kpermissions\x81DpullEknown\xa2Dargs\xa1Enodes\x81HdeadbeefKpermissions\x81DpullFlookup\xa2Dargs\xa1CkeyFlegacyKpermissions\x81DpullGpushkey\xa2Dargs\xa4CkeyFlegacyCnewFlegacyColdFlegacyInamespaceFlegacyKpermissions\x81DpushHlistkeys\xa2Dargs\xa1InamespaceBnsKpermissions\x81DpullHunbundle\xa2Dargs\xa1EheadsFlegacyKpermissions\x81DpushIbranchmap\xa2Dargs\xa0Kpermissions\x81DpullIgetbundle\xa2Dargs\xa1A*FlegacyKpermissions\x81DpullLcapabilities\xa2Dargs\xa0Kpermissions\x81DpullKcompression\x82\xa1DnameDzstd\xa1DnameDzlib
33 s> \xa2Hcommands\xa9Eheads\xa2Dargs\xa1Jpubliconly\xf4Kpermissions\x81DpullEknown\xa2Dargs\xa1Enodes\x81HdeadbeefKpermissions\x81DpullFlookup\xa2Dargs\xa1CkeyFlegacyKpermissions\x81DpullGpushkey\xa2Dargs\xa4CkeyCkeyCnewCnewColdColdInamespaceBnsKpermissions\x81DpullHlistkeys\xa2Dargs\xa1InamespaceBnsKpermissions\x81DpullHunbundle\xa2Dargs\xa1EheadsFlegacyKpermissions\x81DpushIbranchmap\xa2Dargs\xa0Kpermissions\x81DpullIgetbundle\xa2Dargs\xa1A*FlegacyKpermissions\x81DpullLcapabilities\xa2Dargs\xa0Kpermissions\x81DpullKcompression\x82\xa1DnameDzstd\xa1DnameDzlib
34 s> \r\n
34 s> \r\n
35 received frame(size=*; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) (glob)
35 received frame(size=*; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) (glob)
36 s> 0\r\n
36 s> 0\r\n
37 s> \r\n
37 s> \r\n
38 response: [{b'commands': {b'branchmap': {b'args': {}, b'permissions': [b'pull']}, b'capabilities': {b'args': {}, b'permissions': [b'pull']}, b'getbundle': {b'args': {b'*': b'legacy'}, b'permissions': [b'pull']}, b'heads': {b'args': {b'publiconly': False}, b'permissions': [b'pull']}, b'known': {b'args': {b'nodes': [b'deadbeef']}, b'permissions': [b'pull']}, b'listkeys': {b'args': {b'namespace': b'ns'}, b'permissions': [b'pull']}, b'lookup': {b'args': {b'key': b'legacy'}, b'permissions': [b'pull']}, b'pushkey': {b'args': {b'key': b'legacy', b'namespace': b'legacy', b'new': b'legacy', b'old': b'legacy'}, b'permissions': [b'push']}, b'unbundle': {b'args': {b'heads': b'legacy'}, b'permissions': [b'push']}}, b'compression': [{b'name': b'zstd'}, {b'name': b'zlib'}]}]
38 response: [{b'commands': {b'branchmap': {b'args': {}, b'permissions': [b'pull']}, b'capabilities': {b'args': {}, b'permissions': [b'pull']}, b'getbundle': {b'args': {b'*': b'legacy'}, b'permissions': [b'pull']}, b'heads': {b'args': {b'publiconly': False}, b'permissions': [b'pull']}, b'known': {b'args': {b'nodes': [b'deadbeef']}, b'permissions': [b'pull']}, b'listkeys': {b'args': {b'namespace': b'ns'}, b'permissions': [b'pull']}, b'lookup': {b'args': {b'key': b'legacy'}, b'permissions': [b'pull']}, b'pushkey': {b'args': {b'key': b'key', b'namespace': b'ns', b'new': b'new', b'old': b'old'}, b'permissions': [b'pull']}, b'unbundle': {b'args': {b'heads': b'legacy'}, b'permissions': [b'push']}}, b'compression': [{b'name': b'zstd'}, {b'name': b'zlib'}]}]
39
39
40 $ cat error.log
40 $ cat error.log
General Comments 0
You need to be logged in to leave comments. Login now