Mercurial > hg
diff mercurial/sshpeer.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 | e826fe7a08c7 |
children | 3e1688711efd |
line wrap: on
line diff
--- a/mercurial/sshpeer.py Thu Apr 05 17:51:10 2018 +0200 +++ b/mercurial/sshpeer.py Sat Mar 24 17:57:22 2018 +0100 @@ -163,6 +163,17 @@ return proc, stdin, stdout, stderr +def _clientcapabilities(): + """Return list of capabilities of this client. + + Returns a list of capabilities that are supported by this client. + """ + protoparams = [] + comps = [e.wireprotosupport().name for e in + util.compengines.supportedwireengines(util.CLIENTROLE)] + protoparams.append('comp=%s' % ','.join(comps)) + return protoparams + def _performhandshake(ui, stdin, stdout, stderr): def badresponse(): # Flush any output on stderr. @@ -609,4 +620,15 @@ proc, stdin, stdout, stderr = _makeconnection(ui, sshcmd, args, remotecmd, remotepath, sshenv) - return makepeer(ui, path, proc, stdin, stdout, stderr) + peer = makepeer(ui, path, proc, stdin, stdout, stderr) + + # Finally, if supported by the server, notify it about our own + # capabilities. + if 'protocaps' in peer.capabilities(): + try: + peer._call("protocaps", caps=' '.join(_clientcapabilities())) + except IOError: + peer._cleanup() + raise error.RepoError(_('capability exchange failed')) + + return peer