Show More
@@ -42,23 +42,30 b' def hash(text, p1, p2):' | |||
|
42 | 42 | |
|
43 | 43 | def compress(text): |
|
44 | 44 | """ generate a possibly-compressed representation of text """ |
|
45 |
if not text: |
|
|
45 | if not text: | |
|
46 | return ("", text) | |
|
46 | 47 | if len(text) < 44: |
|
47 |
if text[0] == '\0': |
|
|
48 | if text[0] == '\0': | |
|
49 | return ("", text) | |
|
48 | 50 | return ('u', text) |
|
49 | 51 | bin = zlib.compress(text) |
|
50 | 52 | if len(bin) > len(text): |
|
51 |
if text[0] == '\0': |
|
|
53 | if text[0] == '\0': | |
|
54 | return ("", text) | |
|
52 | 55 | return ('u', text) |
|
53 | 56 | return ("", bin) |
|
54 | 57 | |
|
55 | 58 | def decompress(bin): |
|
56 | 59 | """ decompress the given input """ |
|
57 |
if not bin: |
|
|
60 | if not bin: | |
|
61 | return bin | |
|
58 | 62 | t = bin[0] |
|
59 |
if t == '\0': |
|
|
60 | if t == 'x': return zlib.decompress(bin) | |
|
61 |
if t == ' |
|
|
63 | if t == '\0': | |
|
64 | return bin | |
|
65 | if t == 'x': | |
|
66 | return zlib.decompress(bin) | |
|
67 | if t == 'u': | |
|
68 | return bin[1:] | |
|
62 | 69 | raise RevlogError(_("unknown compression type %r") % t) |
|
63 | 70 | |
|
64 | 71 | indexformatv0 = ">4l20s20s20s" |
@@ -106,7 +113,8 b' class lazyparser(object):' | |||
|
106 | 113 | which is fairly slow. loadmap can load up just the node map, |
|
107 | 114 | which takes much less time. |
|
108 | 115 | """ |
|
109 |
if self.allmap: |
|
|
116 | if self.allmap: | |
|
117 | return | |
|
110 | 118 | end = self.datasize |
|
111 | 119 | self.allmap = 1 |
|
112 | 120 | cur = 0 |
@@ -126,7 +134,8 b' class lazyparser(object):' | |||
|
126 | 134 | cur += blocksize |
|
127 | 135 | |
|
128 | 136 | def loadblock(self, blockstart, blocksize, data=None): |
|
129 |
if self.all: |
|
|
137 | if self.all: | |
|
138 | return | |
|
130 | 139 | if data is None: |
|
131 | 140 | self.dataf.seek(blockstart) |
|
132 | 141 | if blockstart + blocksize > self.datasize: |
@@ -151,7 +160,8 b' class lazyparser(object):' | |||
|
151 | 160 | |
|
152 | 161 | def findnode(self, node): |
|
153 | 162 | """search backwards through the index file for a specific node""" |
|
154 |
if self.allmap: |
|
|
163 | if self.allmap: | |
|
164 | return None | |
|
155 | 165 | |
|
156 | 166 | # hg log will cause many many searches for the manifest |
|
157 | 167 | # nodes. After we get called a few times, just load the whole |
@@ -194,7 +204,8 b' class lazyparser(object):' | |||
|
194 | 204 | return None |
|
195 | 205 | |
|
196 | 206 | def loadindex(self, i=None, end=None): |
|
197 |
if self.all: |
|
|
207 | if self.all: | |
|
208 | return | |
|
198 | 209 | all = False |
|
199 | 210 | if i == None: |
|
200 | 211 | blockstart = 0 |
@@ -213,7 +224,8 b' class lazyparser(object):' | |||
|
213 | 224 | while blockstart < end: |
|
214 | 225 | self.loadblock(blockstart, blocksize) |
|
215 | 226 | blockstart += blocksize |
|
216 |
if all: |
|
|
227 | if all: | |
|
228 | self.all = True | |
|
217 | 229 | |
|
218 | 230 | class lazyindex(object): |
|
219 | 231 | """a lazy version of the index array""" |
@@ -277,8 +289,10 b' class lazymap(object):' | |||
|
277 | 289 | def __delitem__(self, key): |
|
278 | 290 | del self.p.map[key] |
|
279 | 291 | |
|
280 |
class RevlogError(Exception): |
|
|
281 | class LookupError(RevlogError): pass | |
|
292 | class RevlogError(Exception): | |
|
293 | pass | |
|
294 | class LookupError(RevlogError): | |
|
295 | pass | |
|
282 | 296 | |
|
283 | 297 | def getoffset(q): |
|
284 | 298 | if q & 0xFFFF: |
@@ -474,17 +488,20 b' class revlog(object):' | |||
|
474 | 488 | self.nodemap.p.loadmap() |
|
475 | 489 | self.nodemap = self.nodemap.p.map |
|
476 | 490 | |
|
477 | def _inline(self): return self.version & REVLOGNGINLINEDATA | |
|
491 | def _inline(self): | |
|
492 | return self.version & REVLOGNGINLINEDATA | |
|
493 | def tip(self): | |
|
494 | return self.node(len(self.index) - 2) | |
|
495 | def count(self): | |
|
496 | return len(self.index) - 1 | |
|
478 | 497 | |
|
479 | def tip(self): return self.node(len(self.index) - 2) | |
|
480 | def count(self): return len(self.index) - 1 | |
|
481 | def node(self, rev): | |
|
482 | return self.index[rev][7] | |
|
483 | 498 | def rev(self, node): |
|
484 | 499 | try: |
|
485 | 500 | return self.nodemap[node] |
|
486 | 501 | except KeyError: |
|
487 | 502 | raise LookupError(_('%s: no node %s') % (self.indexfile, hex(node))) |
|
503 | def node(self, rev): | |
|
504 | return self.index[rev][7] | |
|
488 | 505 | def linkrev(self, node): |
|
489 | 506 | return self.index[self.rev(node)][4] |
|
490 | 507 | def parents(self, node): |
@@ -494,7 +511,12 b' class revlog(object):' | |||
|
494 | 511 | return self.index[rev][5:7] |
|
495 | 512 | def start(self, rev): |
|
496 | 513 | return getoffset(self.index[rev][0]) |
|
497 | def end(self, rev): return self.start(rev) + self.length(rev) | |
|
514 | def end(self, rev): | |
|
515 | return self.start(rev) + self.length(rev) | |
|
516 | def length(self, rev): | |
|
517 | return self.index[rev][1] | |
|
518 | def base(self, rev): | |
|
519 | return self.index[rev][3] | |
|
498 | 520 | |
|
499 | 521 | def size(self, rev): |
|
500 | 522 | """return the length of the uncompressed text for a given revision""" |
@@ -525,11 +547,6 b' class revlog(object):' | |||
|
525 | 547 | return l |
|
526 | 548 | """ |
|
527 | 549 | |
|
528 | def length(self, rev): | |
|
529 | return self.index[rev][1] | |
|
530 | def base(self, rev): | |
|
531 | return self.index[rev][3] | |
|
532 | ||
|
533 | 550 | def reachable(self, node, stop=None): |
|
534 | 551 | """return a hash of all nodes ancestral to a given node, including |
|
535 | 552 | the node itself, stopping when stop is matched""" |
@@ -764,9 +781,12 b' class revlog(object):' | |||
|
764 | 781 | try: |
|
765 | 782 | # str(rev) |
|
766 | 783 | rev = int(id) |
|
767 |
if str(rev) != id: |
|
|
768 | if rev < 0: rev = self.count() + rev | |
|
769 | if rev < 0 or rev >= self.count(): raise ValueError | |
|
784 | if str(rev) != id: | |
|
785 | raise ValueError | |
|
786 | if rev < 0: | |
|
787 | rev = self.count() + rev | |
|
788 | if rev < 0 or rev >= self.count(): | |
|
789 | raise ValueError | |
|
770 | 790 | return self.node(rev) |
|
771 | 791 | except (ValueError, OverflowError): |
|
772 | 792 | pass |
@@ -800,7 +820,6 b' class revlog(object):' | |||
|
800 | 820 | - revision number or str(revision number) |
|
801 | 821 | - nodeid or subset of hex nodeid |
|
802 | 822 | """ |
|
803 | ||
|
804 | 823 | n = self._match(id) |
|
805 | 824 | if n is not None: |
|
806 | 825 | return n |
@@ -851,11 +870,6 b' class revlog(object):' | |||
|
851 | 870 | loadcache(df) |
|
852 | 871 | offset = 0 |
|
853 | 872 | |
|
854 | #def checkchunk(): | |
|
855 | # df = self.opener(self.datafile) | |
|
856 | # df.seek(start) | |
|
857 | # return df.read(length) | |
|
858 | #assert s == checkchunk() | |
|
859 | 873 | return decompress(self._io.chunkcache[1][offset:offset + length]) |
|
860 | 874 | |
|
861 | 875 | def delta(self, node): |
@@ -875,8 +889,10 b' class revlog(object):' | |||
|
875 | 889 | |
|
876 | 890 | def revision(self, node): |
|
877 | 891 | """return an uncompressed revision of a given""" |
|
878 |
if node == nullid: |
|
|
879 | if self.cache and self.cache[0] == node: return self.cache[2] | |
|
892 | if node == nullid: | |
|
893 | return "" | |
|
894 | if self.cache and self.cache[0] == node: | |
|
895 | return self.cache[2] | |
|
880 | 896 | |
|
881 | 897 | # look up what we need to read |
|
882 | 898 | text = None |
@@ -978,9 +994,12 b' class revlog(object):' | |||
|
978 | 994 | return self._addrevision(text, transaction, link, p1, p2, d, ifh, dfh) |
|
979 | 995 | |
|
980 | 996 | def _addrevision(self, text, transaction, link, p1, p2, d, ifh, dfh): |
|
981 |
if text is None: |
|
|
982 | if p1 is None: p1 = self.tip() | |
|
983 |
if p |
|
|
997 | if text is None: | |
|
998 | text = "" | |
|
999 | if p1 is None: | |
|
1000 | p1 = self.tip() | |
|
1001 | if p2 is None: | |
|
1002 | p2 = nullid | |
|
984 | 1003 | |
|
985 | 1004 | node = hash(text, p1, p2) |
|
986 | 1005 |
General Comments 0
You need to be logged in to leave comments.
Login now