Make compression more intelligent:

- we don't attempt to compress things under 44 bytes (empirical)
- we check whether larger objects actually compress
- we tag objects to indicate their compression
  NUL means uncompressed and starts with NUL
  x means gzipped and starts with x (handy)
  u means uncompressed, drop the u
This commit is contained in:
mpm@selenic.com 2005-05-20 17:31:12 -08:00
parent cb09188319
commit 8b0e7913c6

View File

@ -16,10 +16,23 @@ def bin(node): return binascii.unhexlify(node)
def short(node): return hex(node[:4])
def compress(text):
return zlib.compress(text)
if not text: return text
if len(text) < 44:
if text[0] == '\0': return text
return 'u' + text
bin = zlib.compress(text)
if len(bin) > len(text):
if text[0] == '\0': return text
return 'u' + text
return bin
def decompress(bin):
return zlib.decompress(bin)
if not bin: return bin
t = bin[0]
if t == '\0': return bin
if t == 'x': return zlib.decompress(bin)
if t == 'u': return bin[1:]
raise "unknown compression type %s" % t
def hash(text, p1, p2):
l = [p1, p2]