Mercurial > public > mercurial-scm > hg
changeset 52915:fdae7c26d038
chunkbuffer: provide a "__iter__" pass through
If the consumer just want to iterate over chunk of arbitrary size, the chunk
buffer is just an overhead. So we provide a way to bypass it in such cases.
It is put to use in the next changesets.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 27 Jan 2025 18:08:19 +0100 |
parents | d5ae681834e8 |
children | f863fc99bef9 |
files | mercurial/util.py |
diffstat | 1 files changed, 10 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/util.py Mon Jan 20 17:05:22 2025 +0100 +++ b/mercurial/util.py Mon Jan 27 18:08:19 2025 +0100 @@ -2797,6 +2797,16 @@ self._queue = collections.deque() self._chunkoffset = 0 + def __iter__(self): + while self._queue: + chunk = self._queue.popleft() + if self._chunkoffset: + yield chunk[self._chunkoffset :] + else: + yield chunk + self._chunkoffset = 0 + yield from self.iter + 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.