Patchwork [06,of,10] delta: move some delta chain related computation earlier in deltainfo

login
register
mail settings
Submitter Pierre-Yves David
Date June 13, 2019, 1:23 p.m.
Message ID <ea4affeead3ac4635ef2.1560432181@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/40488/
State Accepted
Headers show

Comments

Pierre-Yves David - June 13, 2019, 1:23 p.m.
# HG changeset patch
# User Valentin Gatien-Baron <vgatien-baron@janestreet.com>
# Date 1548106576 -3600
#      Mon Jan 21 22:36:16 2019 +0100
# Node ID ea4affeead3ac4635ef23d351791c483bc9b462d
# Parent  c1659d13be53808661913cfd5b552bbbe4df9f1d
# EXP-Topic delta-extra
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ea4affeead3a
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.

Patch

diff --git a/mercurial/revlogutils/deltas.py b/mercurial/revlogutils/deltas.py
--- a/mercurial/revlogutils/deltas.py
+++ b/mercurial/revlogutils/deltas.py
@@ -932,6 +932,21 @@  class deltacomputer(object):
 
     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 @@  class deltacomputer(object):
                 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)