Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 7109:528b7fc1216c
use the new parseindex implementation C in parsers
author | Bernhard Leiner <bleiner@gmail.com> |
---|---|
date | Fri, 17 Oct 2008 00:24:22 +0200 |
parents | c57b30f1bc15 |
children | 9f0e52e1df77 |
comparison
equal
deleted
inserted
replaced
7108:1ca878d7b849 | 7109:528b7fc1216c |
---|---|
10 of the GNU General Public License, incorporated herein by reference. | 10 of the GNU General Public License, incorporated herein by reference. |
11 """ | 11 """ |
12 | 12 |
13 from node import bin, hex, nullid, nullrev, short | 13 from node import bin, hex, nullid, nullrev, short |
14 from i18n import _ | 14 from i18n import _ |
15 import changegroup, errno, ancestor, mdiff | 15 import changegroup, errno, ancestor, mdiff, parsers |
16 import struct, util, zlib | 16 import struct, util, zlib |
17 | 17 |
18 _pack = struct.pack | 18 _pack = struct.pack |
19 _unpack = struct.unpack | 19 _unpack = struct.unpack |
20 _compress = zlib.compress | 20 _compress = zlib.compress |
372 type = gettype(e[0]) | 372 type = gettype(e[0]) |
373 e[0] = offset_type(0, type) | 373 e[0] = offset_type(0, type) |
374 index[0] = e | 374 index[0] = e |
375 return index, nodemap, None | 375 return index, nodemap, None |
376 | 376 |
377 s = self.size | |
378 cache = None | |
379 index = [] | |
380 nodemap = {nullid: nullrev} | |
381 n = off = 0 | |
382 # if we're not using lazymap, always read the whole index | |
383 data = fp.read() | 377 data = fp.read() |
384 l = len(data) - s | 378 # call the C implementation to parse the index data |
385 append = index.append | 379 index, nodemap, cache = parsers.parse_index(data, inline) |
386 if inline: | |
387 cache = (0, data) | |
388 while off <= l: | |
389 e = _unpack(indexformatng, data[off:off + s]) | |
390 nodemap[e[7]] = n | |
391 append(e) | |
392 n += 1 | |
393 if e[1] < 0: | |
394 break | |
395 off += e[1] + s | |
396 else: | |
397 while off <= l: | |
398 e = _unpack(indexformatng, data[off:off + s]) | |
399 nodemap[e[7]] = n | |
400 append(e) | |
401 n += 1 | |
402 off += s | |
403 | |
404 e = list(index[0]) | |
405 type = gettype(e[0]) | |
406 e[0] = offset_type(0, type) | |
407 index[0] = e | |
408 | |
409 return index, nodemap, cache | 380 return index, nodemap, cache |
410 | 381 |
411 def packentry(self, entry, node, version, rev): | 382 def packentry(self, entry, node, version, rev): |
412 p = _pack(indexformatng, *entry) | 383 p = _pack(indexformatng, *entry) |
413 if rev == 0: | 384 if rev == 0: |
490 self._io = revlogoldio() | 461 self._io = revlogoldio() |
491 if i: | 462 if i: |
492 d = self._io.parseindex(f, self._inline) | 463 d = self._io.parseindex(f, self._inline) |
493 self.index, self.nodemap, self._chunkcache = d | 464 self.index, self.nodemap, self._chunkcache = d |
494 | 465 |
495 # add the magic null revision at -1 | 466 # add the magic null revision at -1 (if it hasn't been done already) |
496 self.index.append((0, 0, 0, -1, -1, -1, -1, nullid)) | 467 if (self.index == [] or isinstance(self.index, lazyindex) or |
468 self.index[-1][7] != nullid) : | |
469 self.index.append((0, 0, 0, -1, -1, -1, -1, nullid)) | |
497 | 470 |
498 def _loadindex(self, start, end): | 471 def _loadindex(self, start, end): |
499 """load a block of indexes all at once from the lazy parser""" | 472 """load a block of indexes all at once from the lazy parser""" |
500 if isinstance(self.index, lazyindex): | 473 if isinstance(self.index, lazyindex): |
501 self.index.p.loadindex(start, end) | 474 self.index.p.loadindex(start, end) |