Mercurial > hg-stable
changeset 35971: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 | 83d67257ba90 |
children | 31449baf0936 |
files | mercurial/sshpeer.py |
diffstat | 1 files changed, 13 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/sshpeer.py Sun Feb 04 14:02:41 2018 -0800 +++ b/mercurial/sshpeer.py Sun Feb 04 12:55:18 2018 -0800 @@ -121,13 +121,6 @@ self._pipeo = self._pipei = self._pipee = None u = util.url(path, parsequery=False, parsefragment=False) - if u.scheme != 'ssh' or not u.host or u.path is None: - self._abort(error.RepoError(_("couldn't parse location %s") % path)) - - util.checksafessh(path) - - if u.passwd is not None: - self._abort(error.RepoError(_("password in URL not supported"))) self._user = u.user self._host = u.host @@ -371,4 +364,17 @@ self._readerr() def instance(ui, path, create): + """Create an SSH peer. + + The returned object conforms to the ``wireproto.wirepeer`` interface. + """ + u = util.url(path, parsequery=False, parsefragment=False) + if u.scheme != 'ssh' or not u.host or u.path is None: + raise error.RepoError(_("couldn't parse location %s") % path) + + util.checksafessh(path) + + if u.passwd is not None: + raise error.RepoError(_('password in URL not supported')) + return sshpeer(ui, path, create=create)