Mercurial > hg-stable
diff mercurial/wireproto.py @ 37393:afcfdf53e4b5
wireproto: provide accessors for client capabilities
For HTTP, this refactors the existing logic, including the parsing of
the compression engine capability.
For SSH, this adds a ssh-only capability "protocaps" and a command for
informing the server on what the client supports. Since SSH is stateful,
keep track of the capabilities in the server instance.
Differential Revision: https://phab.mercurial-scm.org/D1944
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Sat, 24 Mar 2018 17:57:22 +0100 |
parents | ac666c5c2e0c |
children | 1d459f61b42a |
line wrap: on
line diff
--- a/mercurial/wireproto.py Thu Apr 05 17:51:10 2018 +0200 +++ b/mercurial/wireproto.py Sat Mar 24 17:57:22 2018 +0100 @@ -159,6 +159,18 @@ return ';'.join(cmds) +def clientcompressionsupport(proto): + """Returns a list of compression methods supported by the client. + + Returns a list of the compression methods supported by the client + according to the protocol capabilities. If no such capability has + been announced, fallback to the default of zlib and uncompressed. + """ + for cap in proto.getprotocaps(): + if cap.startswith('comp='): + return cap[5:].split(',') + return ['zlib', 'none'] + # mapping of options accepted by getbundle and their types # # Meant to be extended by extensions. It is extensions responsibility to ensure @@ -1027,6 +1039,13 @@ v = ''.join(b and '1' or '0' for b in repo.known(decodelist(nodes))) return wireprototypes.bytesresponse(v) +@wireprotocommand('protocaps', 'caps', permission='pull', + transportpolicy=POLICY_V1_ONLY) +def protocaps(repo, proto, caps): + if proto.name == wireprototypes.SSHV1: + proto._protocaps = set(caps.split(' ')) + return wireprototypes.bytesresponse('OK') + @wireprotocommand('pushkey', 'namespace key old new', permission='push') def pushkey(repo, proto, namespace, key, old, new): # compatibility with pre-1.8 clients which were accidentally