# HG changeset patch # User Pierre-Yves David # Date 2021-05-27 02:09:30 # Node ID 75e1104f23a2c455359b7aec5cb6636c32c94e96 # Parent 0d0fb091c49f73a3eb6deaaa875f490ea307d7de revlog: use dedicated code for reading sidedata We are about to introduce a new, dedicated, file to store sidedata. Before doing so, we make sidedata reading go through different code as reading data chunk. This will simplify some of the complexity of the next changesets. The reading is very simple right now and will need some improvement later to reuse some of the caching strategy we use for the data file. Differential Revision: https://phab.mercurial-scm.org/D10785 diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -1161,6 +1161,7 @@ coreconfigitem( # keeping references to the affected revlogs, especially memory-wise when # rewriting sidedata. # * introduce a proper solution to reduce the number of filelog related files. +# * use caching for reading sidedata (similar to what we do for data). # * Improvement to consider # - avoid compression header in chunk using the default compression? # - forbid "inline" compression mode entirely? diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -803,6 +803,10 @@ class revlog(object): with func() as fp: yield fp + def _sidedatareadfp(self): + """file object suitable to read sidedata""" + return self._datareadfp() + def tiprev(self): return len(self.index) - 1 @@ -2068,7 +2072,19 @@ class revlog(object): if sidedata_size == 0: return {} - comp_segment = self._getsegment(sidedata_offset, sidedata_size) + # XXX this need caching, as we do for data + with self._sidedatareadfp() as sdf: + sdf.seek(sidedata_offset) + comp_segment = sdf.read(sidedata_size) + + if len(comp_segment) < sidedata_size: + filename = self._datafile + length = sidedata_size + offset = sidedata_offset + got = len(comp_segment) + m = PARTIAL_READ_MSG % (filename, length, offset, got) + raise error.RevlogError(m) + comp = self.index[rev][11] if comp == COMP_MODE_PLAIN: segment = comp_segment