Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 515:03f27b1381f9
Whitespace cleanups
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Whitespace cleanups
manifest hash: ac954bc3a4f034c12638a259ecd65841f5b63c5c
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCwuubywK+sNU5EO8RAluIAJ98XQpNdZUpSmYKgDmrMRlbL76ZzQCfes0t
rknNUN/PhtyA4bzL646dOz4=
=UyCE
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Wed, 29 Jun 2005 10:42:35 -0800 |
parents | 934279f3ca53 |
children | 0e9234a1a3f6 eda4c32c167a |
comparison
equal
deleted
inserted
replaced
514:874e577e332e | 515:03f27b1381f9 |
---|---|
62 self.all = 1 | 62 self.all = 1 |
63 i = 0 | 63 i = 0 |
64 end = self.l | 64 end = self.l |
65 self.revlog.index = self.index | 65 self.revlog.index = self.index |
66 self.revlog.nodemap = self.map | 66 self.revlog.nodemap = self.map |
67 | 67 |
68 while i < end: | 68 while i < end: |
69 d = self.data[i * self.s: (i + 1) * self.s] | 69 d = self.data[i * self.s: (i + 1) * self.s] |
70 e = struct.unpack(indexformat, d) | 70 e = struct.unpack(indexformat, d) |
71 self.index[i] = e | 71 self.index[i] = e |
72 self.map[e[6]] = i | 72 self.map[e[6]] = i |
73 i += 1 | 73 i += 1 |
74 | 74 |
75 class lazyindex: | 75 class lazyindex: |
76 def __init__(self, parser): | 76 def __init__(self, parser): |
77 self.p = parser | 77 self.p = parser |
78 def __len__(self): | 78 def __len__(self): |
79 return len(self.p.index) | 79 return len(self.p.index) |
82 return self.p.index[pos] | 82 return self.p.index[pos] |
83 def __getitem__(self, pos): | 83 def __getitem__(self, pos): |
84 return self.p.index[pos] or self.load(pos) | 84 return self.p.index[pos] or self.load(pos) |
85 def append(self, e): | 85 def append(self, e): |
86 self.p.index.append(e) | 86 self.p.index.append(e) |
87 | 87 |
88 class lazymap: | 88 class lazymap: |
89 def __init__(self, parser): | 89 def __init__(self, parser): |
90 self.p = parser | 90 self.p = parser |
91 def load(self, key): | 91 def load(self, key): |
92 if self.p.all: return | 92 if self.p.all: return |
148 self.index[n] = e | 148 self.index[n] = e |
149 n += 1 | 149 n += 1 |
150 | 150 |
151 self.nodemap = dict(m) | 151 self.nodemap = dict(m) |
152 self.nodemap[nullid] = -1 | 152 self.nodemap[nullid] = -1 |
153 | |
154 | 153 |
155 def tip(self): return self.node(len(self.index) - 1) | 154 def tip(self): return self.node(len(self.index) - 1) |
156 def count(self): return len(self.index) | 155 def count(self): return len(self.index) |
157 def node(self, rev): return (rev < 0) and nullid or self.index[rev][6] | 156 def node(self, rev): return (rev < 0) and nullid or self.index[rev][6] |
158 def rev(self, node): return self.nodemap[node] | 157 def rev(self, node): return self.nodemap[node] |
187 c.append(p) | 186 c.append(p) |
188 continue | 187 continue |
189 elif pn == nullid: | 188 elif pn == nullid: |
190 continue | 189 continue |
191 return c | 190 return c |
192 | 191 |
193 def lookup(self, id): | 192 def lookup(self, id): |
194 try: | 193 try: |
195 rev = int(id) | 194 rev = int(id) |
196 if str(rev) != id: raise ValueError | 195 if str(rev) != id: raise ValueError |
197 if rev < 0: rev = self.count() + rev | 196 if rev < 0: rev = self.count() + rev |
203 if hex(n).startswith(id): | 202 if hex(n).startswith(id): |
204 c.append(n) | 203 c.append(n) |
205 if len(c) > 1: raise KeyError("Ambiguous identifier") | 204 if len(c) > 1: raise KeyError("Ambiguous identifier") |
206 if len(c) < 1: raise KeyError("No match found") | 205 if len(c) < 1: raise KeyError("No match found") |
207 return c[0] | 206 return c[0] |
208 | 207 |
209 return None | 208 return None |
210 | 209 |
211 def diff(self, a, b): | 210 def diff(self, a, b): |
212 return mdiff.textdiff(a, b) | 211 return mdiff.textdiff(a, b) |
213 | 212 |
261 if node != hash(text, p1, p2): | 260 if node != hash(text, p1, p2): |
262 raise IOError("integrity check failed on %s:%d" | 261 raise IOError("integrity check failed on %s:%d" |
263 % (self.datafile, rev)) | 262 % (self.datafile, rev)) |
264 | 263 |
265 self.cache = (node, rev, text) | 264 self.cache = (node, rev, text) |
266 return text | 265 return text |
267 | 266 |
268 def addrevision(self, text, transaction, link, p1=None, p2=None): | 267 def addrevision(self, text, transaction, link, p1=None, p2=None): |
269 if text is None: text = "" | 268 if text is None: text = "" |
270 if p1 is None: p1 = self.tip() | 269 if p1 is None: p1 = self.tip() |
271 if p2 is None: p2 = nullid | 270 if p2 is None: p2 = nullid |
298 offset = 0 | 297 offset = 0 |
299 if t >= 0: | 298 if t >= 0: |
300 offset = self.end(t) | 299 offset = self.end(t) |
301 | 300 |
302 e = (offset, len(data), base, link, p1, p2, node) | 301 e = (offset, len(data), base, link, p1, p2, node) |
303 | 302 |
304 self.index.append(e) | 303 self.index.append(e) |
305 self.nodemap[node] = n | 304 self.nodemap[node] = n |
306 entry = struct.pack(indexformat, *e) | 305 entry = struct.pack(indexformat, *e) |
307 | 306 |
308 transaction.add(self.datafile, e[0]) | 307 transaction.add(self.datafile, e[0]) |
318 dist = {nullid: 0} | 317 dist = {nullid: 0} |
319 for i in xrange(self.count()): | 318 for i in xrange(self.count()): |
320 n = self.node(i) | 319 n = self.node(i) |
321 p1, p2 = self.parents(n) | 320 p1, p2 = self.parents(n) |
322 dist[n] = max(dist[p1], dist[p2]) + 1 | 321 dist[n] = max(dist[p1], dist[p2]) + 1 |
323 | 322 |
324 # traverse ancestors in order of decreasing distance from root | 323 # traverse ancestors in order of decreasing distance from root |
325 def ancestors(node): | 324 def ancestors(node): |
326 # we store negative distances because heap returns smallest member | 325 # we store negative distances because heap returns smallest member |
327 h = [(-dist[node], node)] | 326 h = [(-dist[node], node)] |
328 seen = {} | 327 seen = {} |
439 base = self.base(a) | 438 base = self.base(a) |
440 ta = chunks[self.base(a)] | 439 ta = chunks[self.base(a)] |
441 ta = construct(ta, base, a) | 440 ta = construct(ta, base, a) |
442 else: | 441 else: |
443 ta = "" | 442 ta = "" |
444 | 443 |
445 base = self.base(b) | 444 base = self.base(b) |
446 if a > base: | 445 if a > base: |
447 base = a | 446 base = a |
448 tb = ta | 447 tb = ta |
449 else: | 448 else: |
469 | 468 |
470 # track the base of the current delta log | 469 # track the base of the current delta log |
471 r = self.count() | 470 r = self.count() |
472 t = r - 1 | 471 t = r - 1 |
473 node = nullid | 472 node = nullid |
474 | 473 |
475 base = prev = -1 | 474 base = prev = -1 |
476 start = end = 0 | 475 start = end = 0 |
477 if r: | 476 if r: |
478 start = self.start(self.base(t)) | 477 start = self.start(self.base(t)) |
479 end = self.end(t) | 478 end = self.end(t) |