[PATCH 2 of 3] revlog: return offset from _chunkraw()
Gregory Szorc
gregory.szorc at gmail.com
Sun Nov 22 21:34:09 CST 2015
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1448243191 28800
# Sun Nov 22 17:46:31 2015 -0800
# Node ID 9b10f53e1f1a8ab3850577610498dff590ee8357
# Parent 7783c253a56123557de44802f7ec235e7f33d85c
revlog: return offset from _chunkraw()
A subsequent patch will refactor _chunks() and the calculation of the
offset will no longer occur in that function. Prepare by returning the
offset from _chunkraw().
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1008,38 +1008,42 @@ class revlog(object):
"""Obtain a segment of raw data corresponding to a range of revisions.
Accepts the start and end revisions and an optional already-open
file handle to be used for reading. If the file handle is read, its
seek position will not be preserved.
Requests for data may be satisfied by a cache.
- Returns a str or a buffer instance of raw byte data. Callers will
- need to call ``self.start(rev)`` and ``self.length()`` to determine
- where each revision's data begins and ends.
+ Returns a 2-tuple of (offset, data) for the requested range of
+ revisions. Offset is the integer offset from the beginning of the
+ revlog and data is a str or buffer of the raw byte data.
+
+ Callers will need to call ``self.start(rev)`` and ``self.length()``
+ to determine where each revision's data begins and ends.
"""
start = self.start(startrev)
end = self.end(endrev)
if self._inline:
start += (startrev + 1) * self._io.size
end += (endrev + 1) * self._io.size
length = end - start
- return self._getchunk(start, length, df=df)
+
+ return start, self._getchunk(start, length, df=df)
def _chunk(self, rev, df=None):
"""Obtain a single decompressed chunk for a revision.
Accepts an integer revision and an optional already-open file handle
to be used for reading. If used, the seek position of the file will not
be preserved.
Returns a str holding uncompressed data for the requested revision.
"""
- return decompress(self._chunkraw(rev, rev, df=df))
+ return decompress(self._chunkraw(rev, rev, df=df)[1])
def _chunks(self, revs, df=None):
"""Obtain decompressed chunks for the specified revisions.
Accepts an iterable of numeric revisions that are assumed to be in
ascending order. Also accepts an optional already-open file handle
to be used for reading. If used, the seek position of the file will
not be preserved.
@@ -1060,17 +1064,17 @@ class revlog(object):
l = []
ladd = l.append
# preload the cache
try:
while True:
# ensure that the cache doesn't change out from under us
_cache = self._chunkcache
- self._chunkraw(revs[0], revs[-1], df=df)
+ self._chunkraw(revs[0], revs[-1], df=df)[1]
if _cache == self._chunkcache:
break
offset, data = _cache
except OverflowError:
# issue4215 - we can't cache a run of chunks greater than
# 2G on Windows
return [self._chunk(rev, df=df) for rev in revs]
@@ -1221,17 +1225,17 @@ class revlog(object):
if fp:
fp.flush()
fp.close()
df = self.opener(self.datafile, 'w')
try:
for r in self:
- df.write(self._chunkraw(r, r))
+ df.write(self._chunkraw(r, r)[1])
finally:
df.close()
fp = self.opener(self.indexfile, 'w', atomictemp=True)
self.version &= ~(REVLOGNGINLINEDATA)
self._inline = False
for i in self:
e = self._io.packentry(self.index[i], self.node, self.version, i)
More information about the Mercurial-devel
mailing list