comparison mercurial/revlog.py @ 112:aea6562add6c

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
author mpm@selenic.com
date Fri, 20 May 2005 17:31:12 -0800
parents 3dde7c87e36d
children 39b438eeb25a
comparison
equal deleted inserted replaced
111:2c80f6f8fc08 112:aea6562add6c
14 def hex(node): return binascii.hexlify(node) 14 def hex(node): return binascii.hexlify(node)
15 def bin(node): return binascii.unhexlify(node) 15 def bin(node): return binascii.unhexlify(node)
16 def short(node): return hex(node[:4]) 16 def short(node): return hex(node[:4])
17 17
18 def compress(text): 18 def compress(text):
19 return zlib.compress(text) 19 if not text: return text
20 if len(text) < 44:
21 if text[0] == '\0': return text
22 return 'u' + text
23 bin = zlib.compress(text)
24 if len(bin) > len(text):
25 if text[0] == '\0': return text
26 return 'u' + text
27 return bin
20 28
21 def decompress(bin): 29 def decompress(bin):
22 return zlib.decompress(bin) 30 if not bin: return bin
31 t = bin[0]
32 if t == '\0': return bin
33 if t == 'x': return zlib.decompress(bin)
34 if t == 'u': return bin[1:]
35 raise "unknown compression type %s" % t
23 36
24 def hash(text, p1, p2): 37 def hash(text, p1, p2):
25 l = [p1, p2] 38 l = [p1, p2]
26 l.sort() 39 l.sort()
27 return sha.sha(l[0] + l[1] + text).digest() 40 return sha.sha(l[0] + l[1] + text).digest()