Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 4975:8b7e480a7603
revlog: simplify the v1 immediate parser
- read all the data at once (large files are handled by the lazy parser)
- cache the entire file for inline revlogs
- simplify looping
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 23 Jul 2007 20:44:08 -0500 |
parents | a335345100ba |
children | 79c39cc9ff69 |
comparison
equal
deleted
inserted
replaced
4974:a335345100ba | 4975:8b7e480a7603 |
---|---|
331 return index, nodemap | 331 return index, nodemap |
332 | 332 |
333 s = struct.calcsize(indexformatng) | 333 s = struct.calcsize(indexformatng) |
334 index = [] | 334 index = [] |
335 nodemap = {nullid: nullrev} | 335 nodemap = {nullid: nullrev} |
336 n = 0 | 336 n = off = 0 |
337 leftover = None | 337 # if we're not using lazymap, always read the whole index |
338 while True: | 338 data = fp.read() |
339 if st: | 339 l = len(data) |
340 data = fp.read(65536) | 340 if inline: |
341 else: | 341 self.chunkcache = (0, data) |
342 # hack for httprangereader, it doesn't do partial reads well | 342 while off + s <= l: |
343 data = fp.read() | 343 e = struct.unpack(indexformatng, data[off:off + s]) |
344 if not data: | 344 index.append(e) |
345 break | 345 nodemap[e[-1]] = n |
346 if n == 0 and inline: | 346 n += 1 |
347 # cache the first chunk | 347 off += s |
348 self.chunkcache = (0, data) | 348 if inline: |
349 if leftover: | 349 if e[1] < 0: |
350 data = leftover + data | |
351 leftover = None | |
352 off = 0 | |
353 l = len(data) | |
354 while off < l: | |
355 if l - off < s: | |
356 leftover = data[off:] | |
357 break | 350 break |
358 cur = data[off:off + s] | 351 off += e[1] |
359 off += s | |
360 e = struct.unpack(indexformatng, cur) | |
361 index.append(e) | |
362 nodemap[e[-1]] = n | |
363 n += 1 | |
364 if inline: | |
365 if e[1] < 0: | |
366 break | |
367 off += e[1] | |
368 if off > l: | |
369 # some things don't seek well, just read it | |
370 fp.read(off - l) | |
371 break | |
372 if not st: | |
373 break | |
374 | 352 |
375 e = list(index[0]) | 353 e = list(index[0]) |
376 type = gettype(e[0]) | 354 type = gettype(e[0]) |
377 e[0] = offset_type(0, type) | 355 e[0] = offset_type(0, type) |
378 index[0] = e | 356 index[0] = e |