Patchwork D2032: sshpeer: clean up API for sshpeer.__init__ (API)

login
register
mail settings
Submitter phabricator
Date Feb. 5, 2018, 3:35 a.m.
Message ID <differential-rev-PHID-DREV-mn6bufei2vd6soz55hpp-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27291/
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
  Our refactoring left the state of sshpeer.__init__ in a poor
  state. "create" was no longer used. Process/pipe arguments were
  passed poorly. "name" was really a URL.
  
  This commit cleans all that up.
  
  .. api::
  
    sshpeer.sshpeer.__init__ now receives arguments describing an
    existing connection instead of creating a connection itself.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/sshpeer.py
  tests/test-check-interfaces.py

CHANGE DETAILS




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

Patch

diff --git a/tests/test-check-interfaces.py b/tests/test-check-interfaces.py
--- a/tests/test-check-interfaces.py
+++ b/tests/test-check-interfaces.py
@@ -69,8 +69,8 @@ 
     checkobject(badpeer())
     checkobject(httppeer.httppeer(ui, 'http://localhost'))
     checkobject(localrepo.localpeer(dummyrepo()))
-    checkobject(testingsshpeer(ui, 'ssh://localhost/foo', False,
-                               (None, None, None, None)))
+    checkobject(testingsshpeer(ui, 'ssh://localhost/foo', None, None, None,
+                               None))
     checkobject(bundlerepo.bundlepeer(dummyrepo()))
     checkobject(statichttprepo.statichttppeer(dummyrepo()))
     checkobject(unionrepo.unionpeer(dummyrepo()))
diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -158,12 +158,21 @@ 
     return proc, pipei, pipeo, pipee
 
 class sshpeer(wireproto.wirepeer):
-    def __init__(self, ui, path, create=False, sshstate=None):
-        self._url = path
+    def __init__(self, ui, url, proc, pipei, pipeo, pipee):
+        """Create a peer from an existing SSH connection.
+
+        ``proc`` is a handle on the underlying SSH process.
+        ``pipei``, ``pipeo``, and ``pipee`` are handles on the stdin,
+        stdout, and stderr file descriptors for that process.
+        """
+        self._url = url
         self._ui = ui
         # self._subprocess is unused. Keeping a handle on the process
         # holds a reference and prevents it from being garbage collected.
-        self._subprocess, self._pipei, self._pipeo, self._pipee = sshstate
+        self._subprocess = proc
+        self._pipei = pipei
+        self._pipeo = pipeo
+        self._pipee = pipee
 
         self._validaterepo()
 
@@ -387,6 +396,4 @@ 
     proc, pipei, pipeo, pipee = _makeconnection(ui, sshcmd, args, remotecmd,
                                                 remotepath, sshenv)
 
-    sshstate = (proc, pipei, pipeo, pipee)
-
-    return sshpeer(ui, path, create=create, sshstate=sshstate)
+    return sshpeer(ui, path, proc, pipei, pipeo, pipee)