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