Mercurial > public > mercurial-scm > hg
comparison mercurial/wireproto.py @ 37533:df4985497986
wireproto: implement capabilities for wire protocol v2
The capabilities mechanism for wire protocol version 2 represents a
clean break from version 1.
Instead of effectively exchanging a set of capabilities, we're
exchanging a rich data structure.
This data structure currently contains information about
every available command, including its accepted arguments. It also
contains information about supported compression formats.
Exposing information about supported commands will allow clients
to automatically generate bindings to the server. Clients will be
able to do things like detect when they are attempting to run a
command that isn't known to the server. Exposing the required
permissions to run a command can be used by clients to determine if
they have privileges to call a command before actually calling it.
We could potentially even have clients send credentials
preemptively without waiting for the server to deny the command
request. Lots of potential here.
The data returned by this command will likely evolve heavily. So we
shouldn't bikeshed the implementation just yet.
Differential Revision: https://phab.mercurial-scm.org/D3200
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 09 Apr 2018 11:52:31 -0700 |
parents | aacfca6f9767 |
children | 465187fec06f |
comparison
equal
deleted
inserted
replaced
37532:8475c9bf096d | 37533:df4985497986 |
---|---|
901 | 901 |
902 return proto.addcapabilities(repo, caps) | 902 return proto.addcapabilities(repo, caps) |
903 | 903 |
904 # If you are writing an extension and consider wrapping this function. Wrap | 904 # If you are writing an extension and consider wrapping this function. Wrap |
905 # `_capabilities` instead. | 905 # `_capabilities` instead. |
906 @wireprotocommand('capabilities', permission='pull') | 906 @wireprotocommand('capabilities', permission='pull', |
907 transportpolicy=POLICY_V1_ONLY) | |
907 def capabilities(repo, proto): | 908 def capabilities(repo, proto): |
908 caps = _capabilities(repo, proto) | 909 caps = _capabilities(repo, proto) |
909 return wireprototypes.bytesresponse(' '.join(sorted(caps))) | 910 return wireprototypes.bytesresponse(' '.join(sorted(caps))) |
910 | 911 |
911 @wireprotocommand('changegroup', 'roots', transportpolicy=POLICY_V1_ONLY, | 912 @wireprotocommand('changegroup', 'roots', transportpolicy=POLICY_V1_ONLY, |
1281 [('message', stringutil.forcebytestr(exc))]) | 1282 [('message', stringutil.forcebytestr(exc))]) |
1282 return wireprototypes.streamreslegacy(gen=bundler.getchunks()) | 1283 return wireprototypes.streamreslegacy(gen=bundler.getchunks()) |
1283 | 1284 |
1284 # Wire protocol version 2 commands only past this point. | 1285 # Wire protocol version 2 commands only past this point. |
1285 | 1286 |
1287 def _capabilitiesv2(repo, proto): | |
1288 """Obtain the set of capabilities for version 2 transports. | |
1289 | |
1290 These capabilities are distinct from the capabilities for version 1 | |
1291 transports. | |
1292 """ | |
1293 compression = [] | |
1294 for engine in supportedcompengines(repo.ui, util.SERVERROLE): | |
1295 compression.append({ | |
1296 b'name': engine.wireprotosupport().name, | |
1297 }) | |
1298 | |
1299 caps = { | |
1300 'commands': {}, | |
1301 'compression': compression, | |
1302 } | |
1303 | |
1304 for command, entry in commandsv2.items(): | |
1305 caps['commands'][command] = { | |
1306 'args': sorted(entry.args.split()) if entry.args else [], | |
1307 'permissions': [entry.permission], | |
1308 } | |
1309 | |
1310 return proto.addcapabilities(repo, caps) | |
1311 | |
1286 @wireprotocommand('branchmap', permission='pull', | 1312 @wireprotocommand('branchmap', permission='pull', |
1287 transportpolicy=POLICY_V2_ONLY) | 1313 transportpolicy=POLICY_V2_ONLY) |
1288 def branchmapv2(repo, proto): | 1314 def branchmapv2(repo, proto): |
1289 branchmap = {encoding.fromlocal(k): v | 1315 branchmap = {encoding.fromlocal(k): v |
1290 for k, v in repo.branchmap().iteritems()} | 1316 for k, v in repo.branchmap().iteritems()} |
1291 | 1317 |
1292 return wireprototypes.cborresponse(branchmap) | 1318 return wireprototypes.cborresponse(branchmap) |
1319 | |
1320 @wireprotocommand('capabilities', permission='pull', | |
1321 transportpolicy=POLICY_V2_ONLY) | |
1322 def capabilitiesv2(repo, proto): | |
1323 caps = _capabilitiesv2(repo, proto) | |
1324 | |
1325 return wireprototypes.cborresponse(caps) | |
1293 | 1326 |
1294 @wireprotocommand('heads', args='publiconly', permission='pull', | 1327 @wireprotocommand('heads', args='publiconly', permission='pull', |
1295 transportpolicy=POLICY_V2_ONLY) | 1328 transportpolicy=POLICY_V2_ONLY) |
1296 def headsv2(repo, proto, publiconly=False): | 1329 def headsv2(repo, proto, publiconly=False): |
1297 if publiconly: | 1330 if publiconly: |