##// END OF EJS Templates
revlog: simplify revlog.__init__...
Matt Mackall -
r4985:e6525e45 default
parent child Browse files
Show More
@@ -309,7 +309,7 b' class revlogoldio(object):'
309 309 def __init__(self):
310 310 self.size = struct.calcsize(indexformatv0)
311 311
312 def parseindex(self, fp, st, inline):
312 def parseindex(self, fp, inline):
313 313 s = self.size
314 314 index = []
315 315 nodemap = {nullid: nullrev}
@@ -333,11 +333,15 b' class revlogio(object):'
333 333 def __init__(self):
334 334 self.size = struct.calcsize(indexformatng)
335 335
336 def parseindex(self, fp, st, inline):
337 if (lazyparser.safe_to_use and not inline and
338 st and st.st_size > 1000000):
336 def parseindex(self, fp, inline):
337 try:
338 size = util.fstat(fp).st_size
339 except AttributeError:
340 size = 0
341
342 if lazyparser.safe_to_use and not inline and size > 1000000:
339 343 # big index, let's parse it on demand
340 parser = lazyparser(fp, st.st_size)
344 parser = lazyparser(fp, size)
341 345 index = lazyindex(parser)
342 346 nodemap = lazymap(parser)
343 347 e = list(index[0])
@@ -409,18 +413,18 b' class revlog(object):'
409 413 self.indexfile = indexfile
410 414 self.datafile = indexfile[:-2] + ".d"
411 415 self.opener = opener
412 self.indexstat = None
413 416 self._cache = None
414 417 self._chunkcache = None
415 self.defversion = REVLOG_DEFAULT_VERSION
418 self.nodemap = {nullid: nullrev}
419 self.index = []
420
421 v = REVLOG_DEFAULT_VERSION
416 422 if hasattr(opener, "defversion"):
417 self.defversion = opener.defversion
418 if self.defversion & REVLOGNG:
419 self.defversion |= REVLOGNGINLINEDATA
420 self._load()
423 v = opener.defversion
424 if v & REVLOGNG:
425 v |= REVLOGNGINLINEDATA
421 426
422 def _load(self):
423 v = self.defversion
427 i = ""
424 428 try:
425 429 f = self.opener(self.indexfile)
426 430 i = f.read(4)
@@ -430,44 +434,28 b' class revlog(object):'
430 434 except IOError, inst:
431 435 if inst.errno != errno.ENOENT:
432 436 raise
433 i = ""
434 else:
435 try:
436 st = util.fstat(f)
437 except AttributeError, inst:
438 st = None
439 else:
440 oldst = self.indexstat
441 if (oldst and st.st_dev == oldst.st_dev
442 and st.st_ino == oldst.st_ino
443 and st.st_mtime == oldst.st_mtime
444 and st.st_ctime == oldst.st_ctime
445 and st.st_size == oldst.st_size):
446 return
447 self.indexstat = st
437
438 self.version = v
439 self._inline = v & REVLOGNGINLINEDATA
448 440 flags = v & ~0xFFFF
449 441 fmt = v & 0xFFFF
450 if fmt == REVLOGV0:
451 if flags:
442 if fmt == REVLOGV0 and flags:
452 443 raise RevlogError(_("index %s unknown flags %#04x for format v0")
453 444 % (self.indexfile, flags >> 16))
454 elif fmt == REVLOGNG:
455 if flags & ~REVLOGNGINLINEDATA:
445 elif fmt == REVLOGNG and flags & ~REVLOGNGINLINEDATA:
456 446 raise RevlogError(_("index %s unknown flags %#04x for revlogng")
457 447 % (self.indexfile, flags >> 16))
458 else:
448 elif fmt > REVLOGNG:
459 449 raise RevlogError(_("index %s unknown format %d")
460 450 % (self.indexfile, fmt))
461 self.version = v
462 self._inline = v & REVLOGNGINLINEDATA
463 self.nodemap = {nullid: nullrev}
464 self.index = []
451
465 452 self._io = revlogio()
466 453 if self.version == REVLOGV0:
467 454 self._io = revlogoldio()
468 455 if i:
469 d = self._io.parseindex(f, st, self._inline)
456 d = self._io.parseindex(f, self._inline)
470 457 self.index, self.nodemap, self._chunkcache = d
458
471 459 # add the magic null revision at -1
472 460 self.index.append((0, 0, 0, -1, -1, -1, -1, nullid))
473 461
General Comments 0
You need to be logged in to leave comments. Login now