##// END OF EJS Templates
Reduce string duplication in compression code...
mason@suse.com -
r1533:3d11f81c default
parent child Browse files
Show More
@@ -31,15 +31,15 b' def hash(text, p1, p2):'
31
31
32 def compress(text):
32 def compress(text):
33 """ generate a possibly-compressed representation of text """
33 """ generate a possibly-compressed representation of text """
34 if not text: return text
34 if not text: return ("", text)
35 if len(text) < 44:
35 if len(text) < 44:
36 if text[0] == '\0': return text
36 if text[0] == '\0': return ("", text)
37 return 'u' + text
37 return ('u', text)
38 bin = zlib.compress(text)
38 bin = zlib.compress(text)
39 if len(bin) > len(text):
39 if len(bin) > len(text):
40 if text[0] == '\0': return text
40 if text[0] == '\0': return ("", text)
41 return 'u' + text
41 return ('u', text)
42 return bin
42 return ("", bin)
43
43
44 def decompress(bin):
44 def decompress(bin):
45 """ decompress the given input """
45 """ decompress the given input """
@@ -543,14 +543,16 b' class revlog:'
543 end = self.end(t)
543 end = self.end(t)
544 if not d:
544 if not d:
545 prev = self.revision(self.tip())
545 prev = self.revision(self.tip())
546 d = self.diff(prev, text)
546 d = self.diff(prev, str(text))
547 data = compress(d)
547 data = compress(d)
548 dist = end - start + len(data)
548 l = len(data[1]) + len(data[0])
549 dist = end - start + l
549
550
550 # full versions are inserted when the needed deltas
551 # full versions are inserted when the needed deltas
551 # become comparable to the uncompressed text
552 # become comparable to the uncompressed text
552 if not n or dist > len(text) * 2:
553 if not n or dist > len(text) * 2:
553 data = compress(text)
554 data = compress(text)
555 l = len(data[1]) + len(data[0])
554 base = n
556 base = n
555 else:
557 else:
556 base = self.base(t)
558 base = self.base(t)
@@ -559,14 +561,17 b' class revlog:'
559 if t >= 0:
561 if t >= 0:
560 offset = self.end(t)
562 offset = self.end(t)
561
563
562 e = (offset, len(data), base, link, p1, p2, node)
564 e = (offset, l, base, link, p1, p2, node)
563
565
564 self.index.append(e)
566 self.index.append(e)
565 self.nodemap[node] = n
567 self.nodemap[node] = n
566 entry = struct.pack(indexformat, *e)
568 entry = struct.pack(indexformat, *e)
567
569
568 transaction.add(self.datafile, e[0])
570 transaction.add(self.datafile, e[0])
569 self.opener(self.datafile, "a").write(data)
571 f = self.opener(self.datafile, "a")
572 if data[0]:
573 f.write(data[0])
574 f.write(data[1])
570 transaction.add(self.indexfile, n * len(entry))
575 transaction.add(self.indexfile, n * len(entry))
571 self.opener(self.indexfile, "a").write(entry)
576 self.opener(self.indexfile, "a").write(entry)
572
577
@@ -801,7 +806,8 b' class revlog:'
801 # current size.
806 # current size.
802
807
803 if chain == prev:
808 if chain == prev:
804 cdelta = compress(delta)
809 tempd = compress(delta)
810 cdelta = tempd[0] + tempd[1]
805
811
806 if chain != prev or (end - start + len(cdelta)) > measure * 2:
812 if chain != prev or (end - start + len(cdelta)) > measure * 2:
807 # flush our writes here so we can read it in revision
813 # flush our writes here so we can read it in revision
General Comments 0
You need to be logged in to leave comments. Login now