The direction looks good. I'd like to see more solid code. Commented below.
Excerpts from Gregory Szorc's message of 2017-03-26 11:56:59 -0700: > + # Retry to get remaining data. In cases where the stream has errored or > + # is at EOF, this will do a bit of redundant work. But it helps prevent > + # intermittent failures and isn't common. So the overhead is acceptable. > + for i in range(3): If "stream.read" does not behave as expected, assume it's totally broken. So we need to reset the retry counter once we got data. Something like: def readexactly(..., retry=3): .... retryremaining = retry while True: chunk = stream.read(left) if not chunk: retryremaining -= 1 if not retryremaining: break retryremaining = retry left -= len(chunk) .... > + chunk = stream.read(left) > + chunks.append(chunk) > + left -= len(chunk) > + assert left >= 0 > + > + if not left: > + break > + > + if left: > raise error.Abort(_("stream ended unexpectedly" > " (got %d bytes, expected %d)") > - % (len(s), n)) > - return s > + % (n - left, n)) > + > + return b''.join(chunks) > > def getchunk(stream): > """return the next chunk from stream as a string""" _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel