# HG changeset patch # User Pierre-Yves David # Date 2014-04-11 05:10:26 # Node ID c848bfd02366b38add0dc264759d2817c85baab2 # Parent 8de8187e6f4821349d24995da9375e17697f2a46 util: support None size in chunkbuffer.read() When no size is provided, read the whole buffer. This aligns with the usual behavior of `read()` in python. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -968,13 +968,15 @@ class chunkbuffer(object): self.iter = splitbig(in_iter) self._queue = deque() - def read(self, l): + def read(self, l=None): """Read L bytes of data from the iterator of chunks of data. - Returns less than L bytes if the iterator runs dry.""" + Returns less than L bytes if the iterator runs dry. + + If size parameter is ommited, read everything""" left = l buf = [] queue = self._queue - while left > 0: + while left is None or left > 0: # refill the queue if not queue: target = 2**18 @@ -987,8 +989,9 @@ class chunkbuffer(object): break chunk = queue.popleft() - left -= len(chunk) - if left < 0: + if left is not None: + left -= len(chunk) + if left is not None and left < 0: queue.appendleft(chunk[left:]) buf.append(chunk[:left]) else: