Show More
@@ -39,7 +39,6 b' from . import (' | |||||
39 |
|
39 | |||
40 | _pack = struct.pack |
|
40 | _pack = struct.pack | |
41 | _unpack = struct.unpack |
|
41 | _unpack = struct.unpack | |
42 | _compress = zlib.compress |
|
|||
43 | _decompress = zlib.decompress |
|
42 | _decompress = zlib.decompress | |
44 |
|
43 | |||
45 | # revlog header flags |
|
44 | # revlog header flags | |
@@ -341,6 +340,10 b' class revlog(object):' | |||||
341 | # revnum -> (chain-length, sum-delta-length) |
|
340 | # revnum -> (chain-length, sum-delta-length) | |
342 | self._chaininfocache = {} |
|
341 | self._chaininfocache = {} | |
343 |
|
342 | |||
|
343 | @util.propertycache | |||
|
344 | def _compressor(self): | |||
|
345 | return util.compengines['zlib'].revlogcompressor() | |||
|
346 | ||||
344 | def tip(self): |
|
347 | def tip(self): | |
345 | return self.node(len(self.index) - 2) |
|
348 | return self.node(len(self.index) - 2) | |
346 | def __contains__(self, rev): |
|
349 | def __contains__(self, rev): | |
@@ -1465,34 +1468,20 b' class revlog(object):' | |||||
1465 | dfh.close() |
|
1468 | dfh.close() | |
1466 | ifh.close() |
|
1469 | ifh.close() | |
1467 |
|
1470 | |||
1468 |
def compress(self, |
|
1471 | def compress(self, data): | |
1469 |
""" |
|
1472 | """Generate a possibly-compressed representation of data.""" | |
1470 |
if not |
|
1473 | if not data: | |
1471 |
return |
|
1474 | return '', data | |
1472 | l = len(text) |
|
1475 | ||
1473 | bin = None |
|
1476 | compressed = self._compressor.compress(data) | |
1474 | if l < 44: |
|
1477 | ||
1475 |
|
|
1478 | if compressed: | |
1476 | elif l > 1000000: |
|
1479 | # The revlog compressor added the header in the returned data. | |
1477 | # zlib makes an internal copy, thus doubling memory usage for |
|
1480 | return '', compressed | |
1478 | # large files, so lets do this in pieces |
|
1481 | ||
1479 | z = zlib.compressobj() |
|
1482 | if data[0] == '\0': | |
1480 |
|
|
1483 | return '', data | |
1481 | pos = 0 |
|
1484 | return 'u', data | |
1482 | while pos < l: |
|
|||
1483 | pos2 = pos + 2**20 |
|
|||
1484 | p.append(z.compress(text[pos:pos2])) |
|
|||
1485 | pos = pos2 |
|
|||
1486 | p.append(z.flush()) |
|
|||
1487 | if sum(map(len, p)) < l: |
|
|||
1488 | bin = "".join(p) |
|
|||
1489 | else: |
|
|||
1490 | bin = _compress(text) |
|
|||
1491 | if bin is None or len(bin) >= l: |
|
|||
1492 | if text[0] == '\0': |
|
|||
1493 | return ("", text) |
|
|||
1494 | return ('u', text) |
|
|||
1495 | return ("", bin) |
|
|||
1496 |
|
1485 | |||
1497 | def decompress(self, data): |
|
1486 | def decompress(self, data): | |
1498 | """Decompress a revlog chunk. |
|
1487 | """Decompress a revlog chunk. |
General Comments 0
You need to be logged in to leave comments.
Login now