# HG changeset patch # User Gregory Szorc # Date 2018-02-04 20:55:18 # Node ID b202d360d2a4e607d39232de3c2f322f7718aef7 # Parent 83d67257ba9007917f6930860263d9fa4ffe4f34 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 diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py --- a/mercurial/sshpeer.py +++ b/mercurial/sshpeer.py @@ -121,13 +121,6 @@ class sshpeer(wireproto.wirepeer): 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 @@ class sshpeer(wireproto.wirepeer): 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)