diff mercurial/sshpeer.py @ 35977:a9cffd14aa04

sshpeer: inline I/O into _validaterepo() 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. Differential Revision: https://phab.mercurial-scm.org/D2033
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 04 Feb 2018 14:10:56 -0800
parents f8f034344b39
children 80a2b8ae42a1
line wrap: on
line diff
--- a/mercurial/sshpeer.py	Mon Feb 05 14:17:24 2018 -0800
+++ b/mercurial/sshpeer.py	Sun Feb 04 14:10:56 2018 -0800
@@ -212,9 +212,28 @@
             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()
 
@@ -222,8 +241,8 @@
         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: