Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 17139:ad1b5e070f16
merge with main
author | Martin Geisler <mg@aragost.com> |
---|---|
date | Thu, 12 Jul 2012 10:03:50 +0200 |
parents | e7167007c083 1028a1c9077a |
children | 3ac9592b7ab4 |
comparison
equal
deleted
inserted
replaced
17138:528cb91a90ee | 17139:ad1b5e070f16 |
---|---|
72 l.sort() | 72 l.sort() |
73 s = _sha(l[0]) | 73 s = _sha(l[0]) |
74 s.update(l[1]) | 74 s.update(l[1]) |
75 s.update(text) | 75 s.update(text) |
76 return s.digest() | 76 return s.digest() |
77 | |
78 def compress(text): | |
79 """ generate a possibly-compressed representation of text """ | |
80 if not text: | |
81 return ("", text) | |
82 l = len(text) | |
83 bin = None | |
84 if l < 44: | |
85 pass | |
86 elif l > 1000000: | |
87 # zlib makes an internal copy, thus doubling memory usage for | |
88 # large files, so lets do this in pieces | |
89 z = zlib.compressobj() | |
90 p = [] | |
91 pos = 0 | |
92 while pos < l: | |
93 pos2 = pos + 2**20 | |
94 p.append(z.compress(text[pos:pos2])) | |
95 pos = pos2 | |
96 p.append(z.flush()) | |
97 if sum(map(len, p)) < l: | |
98 bin = "".join(p) | |
99 else: | |
100 bin = _compress(text) | |
101 if bin is None or len(bin) > l: | |
102 if text[0] == '\0': | |
103 return ("", text) | |
104 return ('u', text) | |
105 return ("", bin) | |
106 | 77 |
107 def decompress(bin): | 78 def decompress(bin): |
108 """ decompress the given input """ | 79 """ decompress the given input """ |
109 if not bin: | 80 if not bin: |
110 return bin | 81 return bin |
1015 finally: | 986 finally: |
1016 if dfh: | 987 if dfh: |
1017 dfh.close() | 988 dfh.close() |
1018 ifh.close() | 989 ifh.close() |
1019 | 990 |
991 def compress(self, text): | |
992 """ generate a possibly-compressed representation of text """ | |
993 if not text: | |
994 return ("", text) | |
995 l = len(text) | |
996 bin = None | |
997 if l < 44: | |
998 pass | |
999 elif l > 1000000: | |
1000 # zlib makes an internal copy, thus doubling memory usage for | |
1001 # large files, so lets do this in pieces | |
1002 z = zlib.compressobj() | |
1003 p = [] | |
1004 pos = 0 | |
1005 while pos < l: | |
1006 pos2 = pos + 2**20 | |
1007 p.append(z.compress(text[pos:pos2])) | |
1008 pos = pos2 | |
1009 p.append(z.flush()) | |
1010 if sum(map(len, p)) < l: | |
1011 bin = "".join(p) | |
1012 else: | |
1013 bin = _compress(text) | |
1014 if bin is None or len(bin) > l: | |
1015 if text[0] == '\0': | |
1016 return ("", text) | |
1017 return ('u', text) | |
1018 return ("", bin) | |
1019 | |
1020 def _addrevision(self, node, text, transaction, link, p1, p2, | 1020 def _addrevision(self, node, text, transaction, link, p1, p2, |
1021 cachedelta, ifh, dfh): | 1021 cachedelta, ifh, dfh): |
1022 """internal function to add revisions to the log | 1022 """internal function to add revisions to the log |
1023 | 1023 |
1024 see addrevision for argument descriptions. | 1024 see addrevision for argument descriptions. |
1047 delta = cachedelta[1] | 1047 delta = cachedelta[1] |
1048 else: | 1048 else: |
1049 t = buildtext() | 1049 t = buildtext() |
1050 ptext = self.revision(self.node(rev)) | 1050 ptext = self.revision(self.node(rev)) |
1051 delta = mdiff.textdiff(ptext, t) | 1051 delta = mdiff.textdiff(ptext, t) |
1052 data = compress(delta) | 1052 data = self.compress(delta) |
1053 l = len(data[1]) + len(data[0]) | 1053 l = len(data[1]) + len(data[0]) |
1054 if basecache[0] == rev: | 1054 if basecache[0] == rev: |
1055 chainbase = basecache[1] | 1055 chainbase = basecache[1] |
1056 else: | 1056 else: |
1057 chainbase = self.chainbase(rev) | 1057 chainbase = self.chainbase(rev) |
1092 cachedelta[1]) | 1092 cachedelta[1]) |
1093 else: | 1093 else: |
1094 textlen = len(text) | 1094 textlen = len(text) |
1095 if d is None or dist > textlen * 2: | 1095 if d is None or dist > textlen * 2: |
1096 text = buildtext() | 1096 text = buildtext() |
1097 data = compress(text) | 1097 data = self.compress(text) |
1098 l = len(data[1]) + len(data[0]) | 1098 l = len(data[1]) + len(data[0]) |
1099 base = chainbase = curr | 1099 base = chainbase = curr |
1100 | 1100 |
1101 e = (offset_type(offset, flags), l, textlen, | 1101 e = (offset_type(offset, flags), l, textlen, |
1102 base, link, p1r, p2r, node) | 1102 base, link, p1r, p2r, node) |