Show More
@@ -75,35 +75,6 b' def hash(text, p1, p2):' | |||
|
75 | 75 | s.update(text) |
|
76 | 76 | return s.digest() |
|
77 | 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 | ||
|
107 | 78 | def decompress(bin): |
|
108 | 79 | """ decompress the given input """ |
|
109 | 80 | if not bin: |
@@ -1008,6 +979,35 b' class revlog(object):' | |||
|
1008 | 979 | dfh.close() |
|
1009 | 980 | ifh.close() |
|
1010 | 981 | |
|
982 | def compress(self, text): | |
|
983 | """ generate a possibly-compressed representation of text """ | |
|
984 | if not text: | |
|
985 | return ("", text) | |
|
986 | l = len(text) | |
|
987 | bin = None | |
|
988 | if l < 44: | |
|
989 | pass | |
|
990 | elif l > 1000000: | |
|
991 | # zlib makes an internal copy, thus doubling memory usage for | |
|
992 | # large files, so lets do this in pieces | |
|
993 | z = zlib.compressobj() | |
|
994 | p = [] | |
|
995 | pos = 0 | |
|
996 | while pos < l: | |
|
997 | pos2 = pos + 2**20 | |
|
998 | p.append(z.compress(text[pos:pos2])) | |
|
999 | pos = pos2 | |
|
1000 | p.append(z.flush()) | |
|
1001 | if sum(map(len, p)) < l: | |
|
1002 | bin = "".join(p) | |
|
1003 | else: | |
|
1004 | bin = _compress(text) | |
|
1005 | if bin is None or len(bin) > l: | |
|
1006 | if text[0] == '\0': | |
|
1007 | return ("", text) | |
|
1008 | return ('u', text) | |
|
1009 | return ("", bin) | |
|
1010 | ||
|
1011 | 1011 | def _addrevision(self, node, text, transaction, link, p1, p2, |
|
1012 | 1012 | cachedelta, ifh, dfh): |
|
1013 | 1013 | """internal function to add revisions to the log |
@@ -1040,7 +1040,7 b' class revlog(object):' | |||
|
1040 | 1040 | t = buildtext() |
|
1041 | 1041 | ptext = self.revision(self.node(rev)) |
|
1042 | 1042 | delta = mdiff.textdiff(ptext, t) |
|
1043 | data = compress(delta) | |
|
1043 | data = self.compress(delta) | |
|
1044 | 1044 | l = len(data[1]) + len(data[0]) |
|
1045 | 1045 | if basecache[0] == rev: |
|
1046 | 1046 | chainbase = basecache[1] |
@@ -1084,7 +1084,7 b' class revlog(object):' | |||
|
1084 | 1084 | textlen = len(text) |
|
1085 | 1085 | if d is None or dist > textlen * 2: |
|
1086 | 1086 | text = buildtext() |
|
1087 | data = compress(text) | |
|
1087 | data = self.compress(text) | |
|
1088 | 1088 | l = len(data[1]) + len(data[0]) |
|
1089 | 1089 | base = chainbase = curr |
|
1090 | 1090 |
General Comments 0
You need to be logged in to leave comments.
Login now