revlog: compute snapshot depth on delta info
authorBoris Feld <boris.feld@octobus.net>
Fri, 20 Jul 2018 14:32:56 +0200
changeset 39154 e0da43e2f71f
parent 39153 9d6fab487c13
child 39155 a43ef77cab1d
revlog: compute snapshot depth on delta info We need the information to be available when choosing delta.
mercurial/revlog.py
--- a/mercurial/revlog.py	Wed Aug 15 12:30:30 2018 +0200
+++ b/mercurial/revlog.py	Fri Jul 20 14:32:56 2018 +0200
@@ -606,6 +606,7 @@
     chainbase = attr.ib()
     chainlen = attr.ib()
     compresseddeltalen = attr.ib()
+    snapshotdepth = attr.ib()
 
 class _deltacomputer(object):
     def __init__(self, revlog):
@@ -736,8 +737,21 @@
         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)
+                          chainbase, chainlen, compresseddeltalen,
+                          snapshotdepth)
 
     def finddeltainfo(self, revinfo, fh):
         """Find an acceptable delta against a candidate revision