Show More
@@ -446,6 +446,24 b' class revlog(object):' | |||||
446 | force_nodemap = opts.get(b'devel-force-nodemap', False) |
|
446 | force_nodemap = opts.get(b'devel-force-nodemap', False) | |
447 | return newversionflags, mmapindexthreshold, force_nodemap |
|
447 | return newversionflags, mmapindexthreshold, force_nodemap | |
448 |
|
448 | |||
|
449 | def _get_data(self, filepath, mmap_threshold): | |||
|
450 | """return a file content with or without mmap | |||
|
451 | ||||
|
452 | If the file is missing return the empty string""" | |||
|
453 | try: | |||
|
454 | with self.opener(filepath) as fp: | |||
|
455 | if mmap_threshold is not None: | |||
|
456 | file_size = self.opener.fstat(fp).st_size | |||
|
457 | if file_size >= mmap_threshold: | |||
|
458 | # TODO: should .close() to release resources without | |||
|
459 | # relying on Python GC | |||
|
460 | return util.buffer(util.mmapread(fp)) | |||
|
461 | return fp.read() | |||
|
462 | except IOError as inst: | |||
|
463 | if inst.errno != errno.ENOENT: | |||
|
464 | raise | |||
|
465 | return b'' | |||
|
466 | ||||
449 | def _loadindex(self): |
|
467 | def _loadindex(self): | |
450 |
|
468 | |||
451 | newversionflags, mmapindexthreshold, force_nodemap = self._init_opts() |
|
469 | newversionflags, mmapindexthreshold, force_nodemap = self._init_opts() | |
@@ -465,27 +483,12 b' class revlog(object):' | |||||
465 |
|
483 | |||
466 | indexdata = b'' |
|
484 | indexdata = b'' | |
467 | self._initempty = True |
|
485 | self._initempty = True | |
468 | try: |
|
486 | indexdata = self._get_data(self._indexfile, mmapindexthreshold) | |
469 | with self._indexfp() as f: |
|
|||
470 | if ( |
|
|||
471 | mmapindexthreshold is not None |
|
|||
472 | and self.opener.fstat(f).st_size >= mmapindexthreshold |
|
|||
473 | ): |
|
|||
474 | # TODO: should .close() to release resources without |
|
|||
475 | # relying on Python GC |
|
|||
476 | indexdata = util.buffer(util.mmapread(f)) |
|
|||
477 | else: |
|
|||
478 | indexdata = f.read() |
|
|||
479 |
|
|
487 | if len(indexdata) > 0: | |
480 |
|
|
488 | versionflags = INDEX_HEADER.unpack(indexdata[:4])[0] | |
481 |
|
|
489 | self._initempty = False | |
482 |
|
|
490 | else: | |
483 |
|
|
491 | versionflags = newversionflags | |
484 | except IOError as inst: |
|
|||
485 | if inst.errno != errno.ENOENT: |
|
|||
486 | raise |
|
|||
487 |
|
||||
488 | versionflags = newversionflags |
|
|||
489 |
|
492 | |||
490 | flags = self._format_flags = versionflags & ~0xFFFF |
|
493 | flags = self._format_flags = versionflags & ~0xFFFF | |
491 | fmt = self._format_version = versionflags & 0xFFFF |
|
494 | fmt = self._format_version = versionflags & 0xFFFF |
General Comments 0
You need to be logged in to leave comments.
Login now