delta: move some delta chain related computation earlier in deltainfo
They are some more optimization change that will make use of this in the
function. So we retrieve the data earlier.
--- a/mercurial/revlogutils/deltas.py Thu Apr 25 22:50:33 2019 +0200
+++ b/mercurial/revlogutils/deltas.py Mon Jan 21 22:36:16 2019 +0100
@@ -932,6 +932,21 @@
def _builddeltainfo(self, revinfo, base, fh):
# can we use the cached delta?
+ revlog = self.revlog
+ chainbase = revlog.chainbase(base)
+ if revlog._generaldelta:
+ deltabase = base
+ else:
+ deltabase = chainbase
+ snapshotdepth = None
+ if revlog._sparserevlog and deltabase == nullrev:
+ snapshotdepth = 0
+ elif revlog._sparserevlog and revlog.issnapshot(deltabase):
+ # A delta chain should always be one full snapshot,
+ # zero or more semi-snapshots, and zero or more deltas
+ p1, p2 = revlog.rev(revinfo.p1), revlog.rev(revinfo.p2)
+ if deltabase not in (p1, p2) and revlog.issnapshot(deltabase):
+ snapshotdepth = len(revlog._deltachain(deltabase)[0])
delta = None
if revinfo.cachedelta:
cachebase, cachediff = revinfo.cachedelta
@@ -945,31 +960,14 @@
delta = revinfo.cachedelta[1]
if delta is None:
delta = self._builddeltadiff(base, revinfo, fh)
- revlog = self.revlog
header, data = revlog.compress(delta)
deltalen = len(header) + len(data)
- chainbase = revlog.chainbase(base)
offset = revlog.end(len(revlog) - 1)
dist = deltalen + offset - revlog.start(chainbase)
- if revlog._generaldelta:
- deltabase = base
- else:
- deltabase = chainbase
chainlen, compresseddeltalen = revlog._chaininfo(base)
chainlen += 1
compresseddeltalen += deltalen
- revlog = self.revlog
- snapshotdepth = None
- if deltabase == nullrev:
- snapshotdepth = 0
- elif revlog._sparserevlog and revlog.issnapshot(deltabase):
- # A delta chain should always be one full snapshot,
- # zero or more semi-snapshots, and zero or more deltas
- p1, p2 = revlog.rev(revinfo.p1), revlog.rev(revinfo.p2)
- if deltabase not in (p1, p2) and revlog.issnapshot(deltabase):
- snapshotdepth = len(revlog._deltachain(deltabase)[0])
-
return _deltainfo(dist, deltalen, (header, data), deltabase,
chainbase, chainlen, compresseddeltalen,
snapshotdepth)