Show More
@@ -349,6 +349,12 b' class sshv1peer(wireproto.wirepeer):' | |||
|
349 | 349 | self._pipee = stderr |
|
350 | 350 | self._caps = caps |
|
351 | 351 | |
|
352 | # Commands that have a "framed" response where the first line of the | |
|
353 | # response contains the length of that response. | |
|
354 | _FRAMED_COMMANDS = { | |
|
355 | 'batch', | |
|
356 | } | |
|
357 | ||
|
352 | 358 | # Begin of _basepeer interface. |
|
353 | 359 | |
|
354 | 360 | @util.propertycache |
@@ -391,26 +397,7 b' class sshv1peer(wireproto.wirepeer):' | |||
|
391 | 397 | |
|
392 | 398 | __del__ = _cleanup |
|
393 | 399 | |
|
394 | def _submitbatch(self, req): | |
|
395 | rsp = self._callstream("batch", cmds=wireproto.encodebatchcmds(req)) | |
|
396 | available = self._getamount() | |
|
397 | # TODO this response parsing is probably suboptimal for large | |
|
398 | # batches with large responses. | |
|
399 | toread = min(available, 1024) | |
|
400 | work = rsp.read(toread) | |
|
401 | available -= toread | |
|
402 | chunk = work | |
|
403 | while chunk: | |
|
404 | while ';' in work: | |
|
405 | one, work = work.split(';', 1) | |
|
406 | yield wireproto.unescapearg(one) | |
|
407 | toread = min(available, 1024) | |
|
408 | chunk = rsp.read(toread) | |
|
409 | available -= toread | |
|
410 | work += chunk | |
|
411 | yield wireproto.unescapearg(work) | |
|
412 | ||
|
413 | def _sendrequest(self, cmd, args): | |
|
400 | def _sendrequest(self, cmd, args, framed=False): | |
|
414 | 401 | if (self.ui.debugflag |
|
415 | 402 | and self.ui.configbool('devel', 'debug.peer-request')): |
|
416 | 403 | dbg = self.ui.debug |
@@ -444,20 +431,27 b' class sshv1peer(wireproto.wirepeer):' | |||
|
444 | 431 | self._pipeo.write(v) |
|
445 | 432 | self._pipeo.flush() |
|
446 | 433 | |
|
434 | # We know exactly how many bytes are in the response. So return a proxy | |
|
435 | # around the raw output stream that allows reading exactly this many | |
|
436 | # bytes. Callers then can read() without fear of overrunning the | |
|
437 | # response. | |
|
438 | if framed: | |
|
439 | amount = self._getamount() | |
|
440 | return util.cappedreader(self._pipei, amount) | |
|
441 | ||
|
447 | 442 | return self._pipei |
|
448 | 443 | |
|
449 | 444 | def _callstream(self, cmd, **args): |
|
450 | 445 | args = pycompat.byteskwargs(args) |
|
451 | return self._sendrequest(cmd, args) | |
|
446 | return self._sendrequest(cmd, args, framed=cmd in self._FRAMED_COMMANDS) | |
|
452 | 447 | |
|
453 | 448 | def _callcompressable(self, cmd, **args): |
|
454 | 449 | args = pycompat.byteskwargs(args) |
|
455 | return self._sendrequest(cmd, args) | |
|
450 | return self._sendrequest(cmd, args, framed=cmd in self._FRAMED_COMMANDS) | |
|
456 | 451 | |
|
457 | 452 | def _call(self, cmd, **args): |
|
458 | 453 | args = pycompat.byteskwargs(args) |
|
459 | self._sendrequest(cmd, args) | |
|
460 | return self._readframed() | |
|
454 | return self._sendrequest(cmd, args, framed=True).read() | |
|
461 | 455 | |
|
462 | 456 | def _callpush(self, cmd, fp, **args): |
|
463 | 457 | r = self._call(cmd, **args) |
General Comments 0
You need to be logged in to leave comments.
Login now