Show More
@@ -43,17 +43,28 b' nullid = "\\0" * 20' | |||
|
43 | 43 | indexformat = ">4l20s20s20s" |
|
44 | 44 | |
|
45 | 45 | class lazyparser: |
|
46 | def __init__(self, data): | |
|
46 | def __init__(self, data, revlog): | |
|
47 | 47 | self.data = data |
|
48 | 48 | self.s = struct.calcsize(indexformat) |
|
49 | 49 | self.l = len(data)/self.s |
|
50 | 50 | self.index = [None] * self.l |
|
51 | 51 | self.map = {nullid: -1} |
|
52 | self.all = 0 | |
|
53 | self.revlog = revlog | |
|
52 | 54 | |
|
53 | def load(self, pos): | |
|
54 | block = pos / 1000 | |
|
55 | i = block * 1000 | |
|
56 | end = min(self.l, i + 1000) | |
|
55 | def load(self, pos=None): | |
|
56 | if self.all: return | |
|
57 | if pos is not None: | |
|
58 | block = pos / 1000 | |
|
59 | i = block * 1000 | |
|
60 | end = min(self.l, i + 1000) | |
|
61 | else: | |
|
62 | self.all = 1 | |
|
63 | i = 0 | |
|
64 | end = self.l | |
|
65 | self.revlog.index = self.index | |
|
66 | self.revlog.nodemap = self.map | |
|
67 | ||
|
57 | 68 | while i < end: |
|
58 | 69 | d = self.data[i * self.s: (i + 1) * self.s] |
|
59 | 70 | e = struct.unpack(indexformat, d) |
@@ -78,16 +89,14 b' class lazymap:' | |||
|
78 | 89 | def __init__(self, parser): |
|
79 | 90 | self.p = parser |
|
80 | 91 | def load(self, key): |
|
92 | if self.p.all: return | |
|
81 | 93 | n = self.p.data.find(key) |
|
82 | 94 | if n < 0: raise KeyError("node " + hex(key)) |
|
83 | 95 | pos = n / self.p.s |
|
84 | 96 | self.p.load(pos) |
|
85 | 97 | def __contains__(self, key): |
|
86 | try: | |
|
87 | self[key] | |
|
88 | return True | |
|
89 | except KeyError: | |
|
90 | return False | |
|
98 | self.p.load() | |
|
99 | return key in self.p.map | |
|
91 | 100 | def __iter__(self): |
|
92 | 101 | for i in xrange(self.p.l): |
|
93 | 102 | try: |
@@ -121,7 +130,7 b' class revlog:' | |||
|
121 | 130 | |
|
122 | 131 | if len(i) > 10000: |
|
123 | 132 | # big index, let's parse it on demand |
|
124 | parser = lazyparser(i) | |
|
133 | parser = lazyparser(i, self) | |
|
125 | 134 | self.index = lazyindex(parser) |
|
126 | 135 | self.nodemap = lazymap(parser) |
|
127 | 136 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now