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