util.chunkbuffer: refactor chunk handling logic
This will make the next patch easier to read. It provides no benefit on
its own.
--- a/mercurial/util.py Mon Oct 05 16:28:12 2015 -0700
+++ b/mercurial/util.py Mon Oct 05 16:34:47 2015 -0700
@@ -1310,13 +1310,20 @@
if not queue:
break
- chunk = queue.popleft()
- left -= len(chunk)
- if left < 0:
+ chunk = queue[0]
+ chunkl = len(chunk)
+
+ # Use full chunk.
+ if left >= chunkl:
+ left -= chunkl
+ queue.popleft()
+ buf.append(chunk)
+ # Partial chunk needed.
+ else:
+ left -= chunkl
+ queue.popleft()
queue.appendleft(chunk[left:])
buf.append(chunk[:left])
- else:
- buf.append(chunk)
return ''.join(buf)