|
7 | 7 |
|
8 | 8 | import mmap
|
9 | 9 | import os
|
| 10 | +import sys |
10 | 11 | import zlib
|
11 | 12 |
|
12 | 13 | from gitdb.fun import (
|
|
30 | 31 | from gitdb.utils.encoding import force_bytes
|
31 | 32 |
|
32 | 33 | has_perf_mod = False
|
| 34 | +PY26 = sys.version_info[:2] < (2, 7) |
33 | 35 | try:
|
34 | 36 | from _perf import apply_delta as c_apply_delta
|
35 | 37 | has_perf_mod = True
|
@@ -275,10 +277,14 @@ def read(self, size=-1):
|
275 | 277 | # We feed possibly overlapping chunks, which is why the unconsumed tail
|
276 | 278 | # has to be taken into consideration, as well as the unused data
|
277 | 279 | # if we hit the end of the stream
|
278 |
| - # NOTE: For some reason, the code worked for a long time with substracting unconsumed_tail |
279 |
| - # Now, however, it really asks for unused_data, and I wonder whether unconsumed_tail still has to |
280 |
| - # be substracted. On the plus side, the tests work, so it seems to be ok for py 2.7 and 3.4 |
281 |
| - self._cbr += len(indata) - len(self._zip.unconsumed_tail) - len(self._zip.unused_data) |
| 280 | + # NOTE: Behavior changed in PY2.7 onward, which requires special handling to make the tests work properly. |
| 281 | + # They are thorough, and I assume it is truly working. |
| 282 | + if PY26: |
| 283 | + unused_datalen = len(self._zip.unconsumed_tail) |
| 284 | + else: |
| 285 | + unused_datalen = len(self._zip.unconsumed_tail) + len(self._zip.unused_data) |
| 286 | + # end handle very special case ... |
| 287 | + self._cbr += len(indata) - unused_datalen |
282 | 288 | self._br += len(dcompdat)
|
283 | 289 |
|
284 | 290 | if dat:
|
@@ -505,7 +511,6 @@ def new(cls, stream_list):
|
505 | 511 | if stream_list[-1].type_id in delta_types:
|
506 | 512 | raise ValueError("Cannot resolve deltas if there is no base object stream, last one was type: %s" % stream_list[-1].type)
|
507 | 513 | # END check stream
|
508 |
| - |
509 | 514 | return cls(stream_list)
|
510 | 515 |
|
511 | 516 | #} END interface
|
|
0 commit comments