changeset 21018:c848bfd02366

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.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 10 Apr 2014 22:10:26 -0700
parents 8de8187e6f48
children 3dc09f831a2e
files mercurial/util.py
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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: