They are multiple motivation to do it:
- The logic is complicated enough to deserver its own method.
- We will need to reuse this once we put a docket in use.
- This split the actual reading from the processing of the read data better.
indygreg | |
Alphare |
hg-reviewers |
They are multiple motivation to do it:
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/revlog.py (43 lines) |
elif self._chunkcachesize & (self._chunkcachesize - 1): | elif self._chunkcachesize & (self._chunkcachesize - 1): | ||||
raise error.RevlogError( | raise error.RevlogError( | ||||
_(b'revlog chunk cache size %r is not a power of 2') | _(b'revlog chunk cache size %r is not a power of 2') | ||||
% self._chunkcachesize | % self._chunkcachesize | ||||
) | ) | ||||
force_nodemap = opts.get(b'devel-force-nodemap', False) | force_nodemap = opts.get(b'devel-force-nodemap', False) | ||||
return newversionflags, mmapindexthreshold, force_nodemap | return newversionflags, mmapindexthreshold, force_nodemap | ||||
def _get_data(self, filepath, mmap_threshold): | |||||
"""return a file content with or without mmap | |||||
If the file is missing return the empty string""" | |||||
try: | |||||
with self.opener(filepath) as fp: | |||||
if mmap_threshold is not None: | |||||
file_size = self.opener.fstat(fp).st_size | |||||
if file_size >= mmap_threshold: | |||||
# TODO: should .close() to release resources without | |||||
# relying on Python GC | |||||
return util.buffer(util.mmapread(fp)) | |||||
return fp.read() | |||||
except IOError as inst: | |||||
if inst.errno != errno.ENOENT: | |||||
raise | |||||
return b'' | |||||
def _loadindex(self): | def _loadindex(self): | ||||
newversionflags, mmapindexthreshold, force_nodemap = self._init_opts() | newversionflags, mmapindexthreshold, force_nodemap = self._init_opts() | ||||
if self.postfix is None: | if self.postfix is None: | ||||
index_file = b'%s.i' % self.radix | index_file = b'%s.i' % self.radix | ||||
data_file = b'%s.d' % self.radix | data_file = b'%s.d' % self.radix | ||||
elif self.postfix == b'a': | elif self.postfix == b'a': | ||||
index_file = b'%s.i.a' % self.radix | index_file = b'%s.i.a' % self.radix | ||||
data_file = b'%s.d' % self.radix | data_file = b'%s.d' % self.radix | ||||
else: | else: | ||||
index_file = b'%s.i.%s' % (self.radix, self.postfix) | index_file = b'%s.i.%s' % (self.radix, self.postfix) | ||||
data_file = b'%s.d.%s' % (self.radix, self.postfix) | data_file = b'%s.d.%s' % (self.radix, self.postfix) | ||||
self._indexfile = index_file | self._indexfile = index_file | ||||
self._datafile = data_file | self._datafile = data_file | ||||
indexdata = b'' | indexdata = b'' | ||||
self._initempty = True | self._initempty = True | ||||
try: | indexdata = self._get_data(self._indexfile, mmapindexthreshold) | ||||
with self._indexfp() as f: | |||||
if ( | |||||
mmapindexthreshold is not None | |||||
and self.opener.fstat(f).st_size >= mmapindexthreshold | |||||
): | |||||
# TODO: should .close() to release resources without | |||||
# relying on Python GC | |||||
indexdata = util.buffer(util.mmapread(f)) | |||||
else: | |||||
indexdata = f.read() | |||||
if len(indexdata) > 0: | if len(indexdata) > 0: | ||||
versionflags = INDEX_HEADER.unpack(indexdata[:4])[0] | versionflags = INDEX_HEADER.unpack(indexdata[:4])[0] | ||||
self._initempty = False | self._initempty = False | ||||
else: | else: | ||||
versionflags = newversionflags | versionflags = newversionflags | ||||
except IOError as inst: | |||||
if inst.errno != errno.ENOENT: | |||||
raise | |||||
versionflags = newversionflags | |||||
flags = self._format_flags = versionflags & ~0xFFFF | flags = self._format_flags = versionflags & ~0xFFFF | ||||
fmt = self._format_version = versionflags & 0xFFFF | fmt = self._format_version = versionflags & 0xFFFF | ||||
if fmt == REVLOGV0: | if fmt == REVLOGV0: | ||||
if flags: | if flags: | ||||
raise error.RevlogError( | raise error.RevlogError( | ||||
_(b'unknown flags (%#04x) in version %d revlog %s') | _(b'unknown flags (%#04x) in version %d revlog %s') |