Patchwork D2027: sshpeer: move URL validation out of sshpeer.__init__

login
register
mail settings
Submitter phabricator
Date Feb. 5, 2018, 3:35 a.m.
Message ID <differential-rev-PHID-DREV-xslc7kiaohfchs7k2d5s-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27286/
State Superseded
Headers show

Comments

phabricator - Feb. 5, 2018, 3:35 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2027

AFFECTED FILES
  mercurial/sshpeer.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -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)