Changeset View
Changeset View
Standalone View
Standalone View
mercurial/revlog.py
Show First 20 Lines • Show All 287 Lines • ▼ Show 20 Line(s) | class revlog(object): | ||||
_flagserrorclass = error.RevlogError | _flagserrorclass = error.RevlogError | ||||
def __init__( | def __init__( | ||||
self, | self, | ||||
opener, | opener, | ||||
target, | target, | ||||
radix, | radix, | ||||
postfix=None, | postfix=None, # only exist for `tmpcensored` now | ||||
checkambig=False, | checkambig=False, | ||||
mmaplargeindex=False, | mmaplargeindex=False, | ||||
censorable=False, | censorable=False, | ||||
upperboundcomp=None, | upperboundcomp=None, | ||||
persistentnodemap=False, | persistentnodemap=False, | ||||
concurrencychecker=None, | concurrencychecker=None, | ||||
trypending=False, | |||||
): | ): | ||||
""" | """ | ||||
create a revlog object | create a revlog object | ||||
opener is a function that abstracts the file opening operation | opener is a function that abstracts the file opening operation | ||||
and can be used to implement COW semantics or the like. | and can be used to implement COW semantics or the like. | ||||
`target`: a (KIND, ID) tuple that identify the content stored in | `target`: a (KIND, ID) tuple that identify the content stored in | ||||
this revlog. It help the rest of the code to understand what the revlog | this revlog. It help the rest of the code to understand what the revlog | ||||
is about without having to resort to heuristic and index filename | is about without having to resort to heuristic and index filename | ||||
analysis. Note: that this must be reliably be set by normal code, but | analysis. Note: that this must be reliably be set by normal code, but | ||||
that test, debug, or performance measurement code might not set this to | that test, debug, or performance measurement code might not set this to | ||||
accurate value. | accurate value. | ||||
""" | """ | ||||
self.upperboundcomp = upperboundcomp | self.upperboundcomp = upperboundcomp | ||||
self.radix = radix | self.radix = radix | ||||
self._docket_file = None | self._docket_file = None | ||||
self._indexfile = None | self._indexfile = None | ||||
self._datafile = None | self._datafile = None | ||||
self._nodemap_file = None | self._nodemap_file = None | ||||
self.postfix = postfix | self.postfix = postfix | ||||
self._trypending = trypending | |||||
self.opener = opener | self.opener = opener | ||||
if persistentnodemap: | if persistentnodemap: | ||||
self._nodemap_file = nodemaputil.get_nodemap_file(self) | self._nodemap_file = nodemaputil.get_nodemap_file(self) | ||||
assert target[0] in ALL_KINDS | assert target[0] in ALL_KINDS | ||||
assert len(target) == 2 | assert len(target) == 2 | ||||
self.target = target | self.target = target | ||||
# When True, indexfile is opened with checkambig=True at writing, to | # When True, indexfile is opened with checkambig=True at writing, to | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Line(s) | def _get_data(self, filepath, mmap_threshold, size=None): | ||||
if inst.errno != errno.ENOENT: | if inst.errno != errno.ENOENT: | ||||
raise | raise | ||||
return b'' | return b'' | ||||
def _loadindex(self): | def _loadindex(self): | ||||
new_header, mmapindexthreshold, force_nodemap = self._init_opts() | new_header, mmapindexthreshold, force_nodemap = self._init_opts() | ||||
if self.postfix is None: | if self.postfix is not None: | ||||
entry_point = b'%s.i' % self.radix | |||||
else: | |||||
entry_point = b'%s.i.%s' % (self.radix, self.postfix) | entry_point = b'%s.i.%s' % (self.radix, self.postfix) | ||||
elif self._trypending and self.opener.exists(b'%s.i.a' % self.radix): | |||||
entry_point = b'%s.i.a' % self.radix | |||||
else: | |||||
entry_point = b'%s.i' % self.radix | |||||
entry_data = b'' | entry_data = b'' | ||||
self._initempty = True | self._initempty = True | ||||
entry_data = self._get_data(entry_point, mmapindexthreshold) | entry_data = self._get_data(entry_point, mmapindexthreshold) | ||||
if len(entry_data) > 0: | if len(entry_data) > 0: | ||||
header = INDEX_HEADER.unpack(entry_data[:4])[0] | header = INDEX_HEADER.unpack(entry_data[:4])[0] | ||||
self._initempty = False | self._initempty = False | ||||
else: | else: | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | def _loadindex(self): | ||||
self._inline = False | self._inline = False | ||||
# generaldelta implied by version 2 revlogs. | # generaldelta implied by version 2 revlogs. | ||||
self._generaldelta = True | self._generaldelta = True | ||||
# the logic for persistent nodemap will be dealt with within the | # the logic for persistent nodemap will be dealt with within the | ||||
# main docket, so disable it for now. | # main docket, so disable it for now. | ||||
self._nodemap_file = None | self._nodemap_file = None | ||||
if self.postfix is None or self.postfix == b'a': | if self.postfix is None: | ||||
self._datafile = b'%s.d' % self.radix | self._datafile = b'%s.d' % self.radix | ||||
else: | else: | ||||
self._datafile = b'%s.d.%s' % (self.radix, self.postfix) | self._datafile = b'%s.d.%s' % (self.radix, self.postfix) | ||||
self.nodeconstants = sha1nodeconstants | self.nodeconstants = sha1nodeconstants | ||||
self.nullid = self.nodeconstants.nullid | self.nullid = self.nodeconstants.nullid | ||||
# sparse-revlog can't be on without general-delta (issue6056) | # sparse-revlog can't be on without general-delta (issue6056) | ||||
▲ Show 20 Lines • Show All 1505 Lines • ▼ Show 20 Line(s) | def _enforceinlinesize(self, tr): | ||||
if new_dfh is not None: | if new_dfh is not None: | ||||
new_dfh.close() | new_dfh.close() | ||||
def _nodeduplicatecallback(self, transaction, node): | def _nodeduplicatecallback(self, transaction, node): | ||||
"""called when trying to add a node already stored.""" | """called when trying to add a node already stored.""" | ||||
@contextlib.contextmanager | @contextlib.contextmanager | ||||
def _writing(self, transaction): | def _writing(self, transaction): | ||||
if self._trypending: | |||||
msg = b'try to write in a `trypending` revlog: %s' | |||||
msg %= self.display_id | |||||
raise error.ProgrammingError(msg) | |||||
if self._writinghandles is not None: | if self._writinghandles is not None: | ||||
yield | yield | ||||
else: | else: | ||||
r = len(self) | r = len(self) | ||||
dsize = 0 | dsize = 0 | ||||
if r: | if r: | ||||
dsize = self.end(r - 1) | dsize = self.end(r - 1) | ||||
dfh = None | dfh = None | ||||
▲ Show 20 Lines • Show All 1169 Lines • Show Last 20 Lines |