Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
35976:f8f034344b39 | 35977:a9cffd14aa04 |
---|---|
210 msg = _("no suitable response from remote hg") | 210 msg = _("no suitable response from remote hg") |
211 hint = self.ui.config("ui", "ssherrorhint") | 211 hint = self.ui.config("ui", "ssherrorhint") |
212 self._abort(error.RepoError(msg, hint=hint)) | 212 self._abort(error.RepoError(msg, hint=hint)) |
213 | 213 |
214 try: | 214 try: |
215 # skip any noise generated by remote shell | 215 pairsarg = '%s-%s' % ('0' * 40, '0' * 40) |
216 self._callstream("hello") | 216 |
217 r = self._callstream("between", pairs=("%s-%s" % ("0"*40, "0"*40))) | 217 handshake = [ |
218 'hello\n', | |
219 'between\n', | |
220 'pairs %d\n' % len(pairsarg), | |
221 pairsarg, | |
222 ] | |
223 | |
224 requestlog = self.ui.configbool('devel', 'debug.peer-request') | |
225 | |
226 if requestlog: | |
227 self.ui.debug('devel-peer-request: hello\n') | |
228 self.ui.debug('sending hello command\n') | |
229 if requestlog: | |
230 self.ui.debug('devel-peer-request: between\n') | |
231 self.ui.debug('devel-peer-request: pairs: %d bytes\n' % | |
232 len(pairsarg)) | |
233 self.ui.debug('sending between command\n') | |
234 | |
235 self._pipeo.write(''.join(handshake)) | |
236 self._pipeo.flush() | |
218 except IOError: | 237 except IOError: |
219 badresponse() | 238 badresponse() |
220 | 239 |
221 lines = ["", "dummy"] | 240 lines = ["", "dummy"] |
222 max_noise = 500 | 241 max_noise = 500 |
223 while lines[-1] and max_noise: | 242 while lines[-1] and max_noise: |
224 try: | 243 try: |
225 l = r.readline() | 244 l = self._pipei.readline() |
226 self._readerr() | 245 _forwardoutput(self.ui, self._pipee) |
227 if lines[-1] == "1\n" and l == "\n": | 246 if lines[-1] == "1\n" and l == "\n": |
228 break | 247 break |
229 if l: | 248 if l: |
230 self.ui.debug("remote: ", l) | 249 self.ui.debug("remote: ", l) |
231 lines.append(l) | 250 lines.append(l) |