util: support None size in chunkbuffer.read()
authorPierre-Yves David <pierre-yves.david@fb.com>
Thu, 10 Apr 2014 22:10:26 -0700
changeset 21018 c848bfd02366
parent 21017 8de8187e6f48
child 21019 3dc09f831a2e
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.
mercurial/util.py
--- 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: