Patchwork D2033: sshpeer: inline I/O into _validaterepo()

login
register
mail settings
Submitter phabricator
Date Feb. 5, 2018, 3:35 a.m.
Message ID <differential-rev-PHID-DREV-yohwucouguqxo3kdppre-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27292/
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 want to move the handshake code out of the peer class so the
  peer factory function can perform the handshake and instantiate
  a proper class depending on the results. To make that refactor
  easier to read, we first inline I/O functionality into
  _validaterepo().
  
  Test output for low-level protocol tests didn't change, thus
  hopefully demonstrating that this refactor didn't change any
  material behavior.
  
  Because we no longer call _callstream(), our test extension for
  monkeypatching the peer had to change its hook point.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/sshpeer.py
  tests/sshprotoext.py

CHANGE DETAILS




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

Patch

diff --git a/tests/sshprotoext.py b/tests/sshprotoext.py
--- a/tests/sshprotoext.py
+++ b/tests/sshprotoext.py
@@ -54,18 +54,11 @@ 
 
 class extrahandshakecommandspeer(sshpeer.sshpeer):
     """An ssh peer that sends extra commands as part of initial handshake."""
-    # There isn't a good hook point. So we wrap _callstream() and inject
-    # logic when the peer says "hello".
-    def _callstream(self, cmd, **args):
-        if cmd != b'hello':
-            return super(extrahandshakecommandspeer, self)._callstream(cmd,
-                                                                       **args)
-
+    def _validaterepo(self):
         mode = self._ui.config(b'sshpeer', b'handshake-mode')
         if mode == b'pre-no-args':
             self._callstream(b'no-args')
-            return super(extrahandshakecommandspeer, self)._callstream(
-                cmd, **args)
+            return super(extrahandshakecommandspeer, self)._validaterepo()
         else:
             raise error.ProgrammingError(b'unknown HANDSHAKECOMMANDMODE: %s' %
                                          mode)
diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -213,18 +213,37 @@ 
             self._abort(error.RepoError(msg, hint=hint))
 
         try:
-            # skip any noise generated by remote shell
-            self._callstream("hello")
-            r = self._callstream("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
+            pairsarg = '%s-%s' % ('0' * 40, '0' * 40)
+
+            handshake = [
+                'hello\n',
+                'between\n',
+                'pairs %d\n' % len(pairsarg),
+                pairsarg,
+            ]
+
+            requestlog = self.ui.configbool('devel', 'debug.peer-request')
+
+            if requestlog:
+                self.ui.debug('devel-peer-request: hello\n')
+            self.ui.debug('sending hello command\n')
+            if requestlog:
+                self.ui.debug('devel-peer-request: between\n')
+                self.ui.debug('devel-peer-request:   pairs: %d bytes\n' %
+                              len(pairsarg))
+            self.ui.debug('sending between command\n')
+
+            self._pipeo.write(''.join(handshake))
+            self._pipeo.flush()
         except IOError:
             badresponse()
 
         lines = ["", "dummy"]
         max_noise = 500
         while lines[-1] and max_noise:
             try:
-                l = r.readline()
-                self._readerr()
+                l = self._pipei.readline()
+                _forwardoutput(self.ui, self._pipee)
                 if lines[-1] == "1\n" and l == "\n":
                     break
                 if l: