comparison 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
comparison
equal deleted inserted replaced
37392:a4f02a17420d 37393:afcfdf53e4b5
160 # feel free to remove buffering and select usage when we ultimately 160 # feel free to remove buffering and select usage when we ultimately
161 # move to threading. 161 # move to threading.
162 stdin, stdout, stderr, proc = procutil.popen4(cmd, bufsize=0, env=sshenv) 162 stdin, stdout, stderr, proc = procutil.popen4(cmd, bufsize=0, env=sshenv)
163 163
164 return proc, stdin, stdout, stderr 164 return proc, stdin, stdout, stderr
165
166 def _clientcapabilities():
167 """Return list of capabilities of this client.
168
169 Returns a list of capabilities that are supported by this client.
170 """
171 protoparams = []
172 comps = [e.wireprotosupport().name for e in
173 util.compengines.supportedwireengines(util.CLIENTROLE)]
174 protoparams.append('comp=%s' % ','.join(comps))
175 return protoparams
165 176
166 def _performhandshake(ui, stdin, stdout, stderr): 177 def _performhandshake(ui, stdin, stdout, stderr):
167 def badresponse(): 178 def badresponse():
168 # Flush any output on stderr. 179 # Flush any output on stderr.
169 _forwardoutput(ui, stderr) 180 _forwardoutput(ui, stderr)
607 raise error.RepoError(_('could not create remote repo')) 618 raise error.RepoError(_('could not create remote repo'))
608 619
609 proc, stdin, stdout, stderr = _makeconnection(ui, sshcmd, args, remotecmd, 620 proc, stdin, stdout, stderr = _makeconnection(ui, sshcmd, args, remotecmd,
610 remotepath, sshenv) 621 remotepath, sshenv)
611 622
612 return makepeer(ui, path, proc, stdin, stdout, stderr) 623 peer = makepeer(ui, path, proc, stdin, stdout, stderr)
624
625 # Finally, if supported by the server, notify it about our own
626 # capabilities.
627 if 'protocaps' in peer.capabilities():
628 try:
629 peer._call("protocaps", caps=' '.join(_clientcapabilities()))
630 except IOError:
631 peer._cleanup()
632 raise error.RepoError(_('capability exchange failed'))
633
634 return peer