comparison mercurial/sshpeer.py @ 35931:b202d360d2a4

sshpeer: move URL validation out of sshpeer.__init__ We will soon have another SSH peer class to support the new version of the SSH protocol. However, we won't know which peer class to instantiate until we perform a handshake on an active connection. This means that we need to move connection establishment and handshake code out of sshpeer.__init__. This commit starts the process of migrating peer creation code out of sshpeer.__init__ into instance(), which is the API for creating peers. The moved code no longer calls _abort(). _abort() runs _cleanup() and raises. _cleanup() only performs actions on self._pipe*. These objects aren't instantiated until we actually connect to the peer. So _abort() was not necessary in the old code. To keep the API the same, __init__() now makes a redundant call to util.url(). This will be fixed in subsequent commits. Differential Revision: https://phab.mercurial-scm.org/D2027
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 04 Feb 2018 12:55:18 -0800
parents b0d2885c5945
children 31449baf0936
comparison
equal deleted inserted replaced
35930:83d67257ba90 35931:b202d360d2a4
119 self._url = path 119 self._url = path
120 self._ui = ui 120 self._ui = ui
121 self._pipeo = self._pipei = self._pipee = None 121 self._pipeo = self._pipei = self._pipee = None
122 122
123 u = util.url(path, parsequery=False, parsefragment=False) 123 u = util.url(path, parsequery=False, parsefragment=False)
124 if u.scheme != 'ssh' or not u.host or u.path is None:
125 self._abort(error.RepoError(_("couldn't parse location %s") % path))
126
127 util.checksafessh(path)
128
129 if u.passwd is not None:
130 self._abort(error.RepoError(_("password in URL not supported")))
131 124
132 self._user = u.user 125 self._user = u.user
133 self._host = u.host 126 self._host = u.host
134 self._port = u.port 127 self._port = u.port
135 self._path = u.path or '.' 128 self._path = u.path or '.'
369 if flush: 362 if flush:
370 self._pipeo.flush() 363 self._pipeo.flush()
371 self._readerr() 364 self._readerr()
372 365
373 def instance(ui, path, create): 366 def instance(ui, path, create):
367 """Create an SSH peer.
368
369 The returned object conforms to the ``wireproto.wirepeer`` interface.
370 """
371 u = util.url(path, parsequery=False, parsefragment=False)
372 if u.scheme != 'ssh' or not u.host or u.path is None:
373 raise error.RepoError(_("couldn't parse location %s") % path)
374
375 util.checksafessh(path)
376
377 if u.passwd is not None:
378 raise error.RepoError(_('password in URL not supported'))
379
374 return sshpeer(ui, path, create=create) 380 return sshpeer(ui, path, create=create)