Skip to content

Commit ed41d2c

Browse files
ByronCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 81cf3e5 commit ed41d2c

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

gitdb/stream.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def read(self, size=-1):
268268
if tail:
269269
# move the window, make it as large as size demands. For code-clarity,
270270
# we just take the chunk from our map again instead of reusing the unconsumed
271-
# tail. The latter one would safe some memory copying, but we could end up
271+
# tail. The latter one would save some memory copying, but we could end up
272272
# with not getting enough data uncompressed, so we had to sort that out as well.
273273
# Now we just assume the worst case, hence the data is uncompressed and the window
274274
# needs to be as large as the uncompressed bytes we want to read.
@@ -313,7 +313,10 @@ def read(self, size=-1):
313313
consumed = len(indata) - unused_datalen
314314
self._cbr += consumed
315315
self._br += len(chunk)
316-
dcompdat += chunk
316+
if chunk:
317+
if not isinstance(dcompdat, bytearray):
318+
dcompdat = bytearray(dcompdat)
319+
dcompdat.extend(chunk)
317320

318321
# Stop when we have enough or there is no path to more output.
319322
# `chunk` may legitimately be empty mid-stream when zlib is

gitdb/test/test_stream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ def test_decompress_reader_chunked_read_does_not_terminate_early(self):
179179
data = b"hello world! " * 1000
180180
zdata = zlib.compress(data)
181181

182-
# Loop with a small chunk size to force many sub-_s recursions.
182+
# Loop with a small chunk size to force many internal read/decompression
183+
# iterations before EOF.
183184
for chunk_size in (1, 4, 16, 64):
184185
reader = DecompressMemMapReader(
185186
zdata, close_on_deletion=False, size=len(data)

0 commit comments

Comments
 (0)