changeset 49791:05db41701ece

find-delta: pass the cache-delta usage policy alongside the cache-delta The idea is to give higher level code more control to what will happens with the cache delta passed. This should help with controling how we treat delta's from different sources. The final goal of this change is to allow for server modes where the client can blindly accept any server delta without regards to any local constraints. This will be implemented in later changesets.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 07 Nov 2022 22:12:59 -0500
parents 4302db0f54c8
children efbbc2f9121e
files mercurial/revlog.py mercurial/revlogutils/__init__.py mercurial/revlogutils/constants.py mercurial/revlogutils/debug.py mercurial/revlogutils/deltas.py
diffstat 5 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Mon Nov 28 18:58:35 2022 +0100
+++ b/mercurial/revlog.py	Mon Nov 07 22:12:59 2022 -0500
@@ -38,6 +38,8 @@
     COMP_MODE_DEFAULT,
     COMP_MODE_INLINE,
     COMP_MODE_PLAIN,
+    DELTA_BASE_REUSE_NO,
+    DELTA_BASE_REUSE_TRY,
     ENTRY_RANK,
     FEATURES_BY_VERSION,
     FLAG_GENERALDELTA,
@@ -2458,6 +2460,16 @@
                 self, write_debug=write_debug
             )
 
+        if cachedelta is not None and len(cachedelta) == 2:
+            # If the cached delta has no information about how it should be
+            # reused, add the default reuse instruction according to the
+            # revlog's configuration.
+            if self._generaldelta and self._lazydeltabase:
+                delta_base_reuse = DELTA_BASE_REUSE_TRY
+            else:
+                delta_base_reuse = DELTA_BASE_REUSE_NO
+            cachedelta = (cachedelta[0], cachedelta[1], delta_base_reuse)
+
         revinfo = revlogutils.revisioninfo(
             node,
             p1,
--- a/mercurial/revlogutils/__init__.py	Mon Nov 28 18:58:35 2022 +0100
+++ b/mercurial/revlogutils/__init__.py	Mon Nov 07 22:12:59 2022 -0500
@@ -67,7 +67,7 @@
     node:       expected hash of the revision
     p1, p2:     parent revs of the revision
     btext:      built text cache consisting of a one-element list
-    cachedelta: (baserev, uncompressed_delta) or None
+    cachedelta: (baserev, uncompressed_delta, usage_mode) or None
     flags:      flags associated to the revision storage
 
     One of btext[0] or cachedelta must be set.
--- a/mercurial/revlogutils/constants.py	Mon Nov 28 18:58:35 2022 +0100
+++ b/mercurial/revlogutils/constants.py	Mon Nov 07 22:12:59 2022 -0500
@@ -301,3 +301,17 @@
 
 
 SPARSE_REVLOG_MAX_CHAIN_LENGTH = 1000
+
+### What should be done with a cached delta and its base ?
+
+# Ignore the cache when considering candidates.
+#
+# The cached delta might be used, but the delta base will not be scheduled for
+# usage earlier than in "normal" order.
+DELTA_BASE_REUSE_NO = 0
+
+# Prioritize trying the cached delta base
+#
+# The delta base will be tested for validy first. So that the cached deltas get
+# used when possible.
+DELTA_BASE_REUSE_TRY = 1
--- a/mercurial/revlogutils/debug.py	Mon Nov 28 18:58:35 2022 +0100
+++ b/mercurial/revlogutils/debug.py	Mon Nov 07 22:12:59 2022 -0500
@@ -646,7 +646,7 @@
         base_text = revlog.revision(base_rev)
         delta = mdiff.textdiff(base_text, full_text)
 
-        cachedelta = (base_rev, delta)
+        cachedelta = (base_rev, delta, constants.DELTA_BASE_REUSE_TRY)
         btext = [None]
 
     revinfo = revlogutils.revisioninfo(
--- a/mercurial/revlogutils/deltas.py	Mon Nov 28 18:58:35 2022 +0100
+++ b/mercurial/revlogutils/deltas.py	Mon Nov 07 22:12:59 2022 -0500
@@ -20,6 +20,7 @@
     COMP_MODE_DEFAULT,
     COMP_MODE_INLINE,
     COMP_MODE_PLAIN,
+    DELTA_BASE_REUSE_NO,
     KIND_CHANGELOG,
     KIND_FILELOG,
     KIND_MANIFESTLOG,
@@ -819,7 +820,7 @@
     # through configuration. Disabling reuse source delta is useful when
     # we want to make sure we recomputed "optimal" deltas.
     debug_info = None
-    if cachedelta and revlog._generaldelta and revlog._lazydeltabase:
+    if cachedelta is not None and cachedelta[2] > DELTA_BASE_REUSE_NO:
         # Assume what we received from the server is a good choice
         # build delta will reuse the cache
         if debug_info is not None: