From patchwork Wed Jan 6 03:52:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1,of,2] revlog: return offset from _chunkraw() From: Gregory Szorc X-Patchwork-Id: 12554 Message-Id: <2506af2e83054d590b9b.1452052332@ubuntu-vm-main> To: mercurial-devel@selenic.com Date: Tue, 05 Jan 2016 19:52:12 -0800 # HG changeset patch # User Gregory Szorc # Date 1452052311 28800 # Tue Jan 05 19:51:51 2016 -0800 # Node ID 2506af2e83054d590b9b12912c91074f5f58a274 # Parent b8405d739149cdd6d8d9bd5e3dd2ad8487b1f09a 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/contrib/perf.py b/contrib/perf.py --- a/contrib/perf.py +++ b/contrib/perf.py @@ -563,17 +563,17 @@ def perfrevlogrevision(ui, repo, file_, r._checkhash(text, node, rev) def dorevision(): if not cache: r.clearcaches() r.revision(node) chain = r._deltachain(rev)[0] - data = r._chunkraw(chain[0], chain[-1]) + data = r._chunkraw(chain[0], chain[-1])[1] bins = r._chunks(chain) text = str(bins[0]) bins = bins[1:] text = mdiff.patches(text, bins) benches = [ (lambda: dorevision(), 'full'), (lambda: dodeltachain(rev), 'deltachain'), diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -1066,38 +1066,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(rev)`` + 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. @@ -1118,17 +1122,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] @@ -1262,17 +1266,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)