Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 52930:e4552f135e35
chunkbuffer: add a "tell()" method on chunk buffer
That method indicate the amount of data read so far. It will be used to limit
the memory usage of the threaded stream-clone application.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 27 Jan 2025 18:18:57 +0100 |
parents | fdae7c26d038 |
children | c92f9edd362a |
line wrap: on
line diff
--- a/mercurial/util.py Tue Jan 21 04:28:11 2025 +0100 +++ b/mercurial/util.py Mon Jan 27 18:18:57 2025 +0100 @@ -2796,16 +2796,25 @@ self.iter = splitbig(in_iter) self._queue = collections.deque() self._chunkoffset = 0 + self._absolute_offset = 0 def __iter__(self): while self._queue: chunk = self._queue.popleft() if self._chunkoffset: - yield chunk[self._chunkoffset :] + d = chunk[self._chunkoffset :] else: - yield chunk + d = chunk + self._absolute_offset += len(d) + yield d self._chunkoffset = 0 - yield from self.iter + for d in self.iter: + self._absolute_offset += len(d) + yield d + + def tell(self) -> int: + """tell how much data we have read so far""" + return self._absolute_offset def read(self, l=None): """Read L bytes of data from the iterator of chunks of data. @@ -2813,7 +2822,9 @@ If size parameter is omitted, read everything""" if l is None: - return b''.join(self.iter) + d = b''.join(self.iter) + self._absolute_offset += len(d) + return d left = l buf = [] @@ -2865,7 +2876,9 @@ self._chunkoffset += left left -= chunkremaining - return b''.join(buf) + d = b''.join(buf) + self._absolute_offset += len(d) + return d def filechunkiter(f, size=131072, limit=None):