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.
--- a/mercurial/util.py Fri Apr 11 15:02:26 2014 -0400
+++ b/mercurial/util.py Thu Apr 10 22:10:26 2014 -0700
@@ -968,13 +968,15 @@
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 @@
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: