changeset 49766:152d9c011bcd

changegroup: add `delta_base_reuse_policy` argument The argument available through function from changegroup.apply to `revlog.apply` allow to override the revlog configuration in terms of delta-base-reuse policy when searching for a delta to store a revision. It will be put to use in the next changesets.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 03 Dec 2022 01:31:23 +0100
parents 4188e75af983
children f1887500f3ec
files mercurial/changegroup.py mercurial/filelog.py mercurial/manifest.py mercurial/revlog.py
diffstat 4 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Sat Dec 03 01:16:22 2022 +0100
+++ b/mercurial/changegroup.py	Sat Dec 03 01:31:23 2022 +0100
@@ -420,6 +420,7 @@
         prog,
         addrevisioncb=None,
         debug_info=None,
+        delta_base_reuse_policy=None,
     ):
         self.callback = prog.increment
         # no need to check for empty manifest group here:
@@ -435,6 +436,7 @@
             trp,
             addrevisioncb=addrevisioncb,
             debug_info=debug_info,
+            delta_base_reuse_policy=delta_base_reuse_policy,
         )
         prog.complete()
         self.callback = None
@@ -448,6 +450,7 @@
         targetphase=phases.draft,
         expectedtotal=None,
         sidedata_categories=None,
+        delta_base_reuse_policy=None,
     ):
         """Add the changegroup returned by source.read() to this repo.
         srctype is a string like 'push', 'pull', or 'unbundle'.  url is
@@ -461,6 +464,12 @@
 
         `sidedata_categories` is an optional set of the remote's sidedata wanted
         categories.
+
+        `delta_base_reuse_policy` is an optional argument, when set to a value
+        it will control the way the delta contained into the bundle are reused
+        when applied in the revlog.
+
+        See `DELTA_BASE_REUSE_*` entry in mercurial.revlogutils.constants.
         """
         repo = repo.unfiltered()
 
@@ -543,6 +552,7 @@
                 addrevisioncb=onchangelog,
                 duplicaterevisioncb=ondupchangelog,
                 debug_info=debug_info,
+                delta_base_reuse_policy=delta_base_reuse_policy,
             ):
                 repo.ui.develwarn(
                     b'applied empty changelog from changegroup',
@@ -591,6 +601,7 @@
                 progress,
                 addrevisioncb=on_manifest_rev,
                 debug_info=debug_info,
+                delta_base_reuse_policy=delta_base_reuse_policy,
             )
 
             needfiles = {}
@@ -628,6 +639,7 @@
                 needfiles,
                 addrevisioncb=on_filelog_rev,
                 debug_info=debug_info,
+                delta_base_reuse_policy=delta_base_reuse_policy,
             )
 
             if sidedata_helpers:
@@ -815,6 +827,7 @@
         prog,
         addrevisioncb=None,
         debug_info=None,
+        delta_base_reuse_policy=None,
     ):
         super(cg3unpacker, self)._unpackmanifests(
             repo,
@@ -823,6 +836,7 @@
             prog,
             addrevisioncb=addrevisioncb,
             debug_info=debug_info,
+            delta_base_reuse_policy=delta_base_reuse_policy,
         )
         for chunkdata in iter(self.filelogheader, {}):
             # If we get here, there are directory manifests in the changegroup
@@ -835,6 +849,7 @@
                 trp,
                 addrevisioncb=addrevisioncb,
                 debug_info=debug_info,
+                delta_base_reuse_policy=delta_base_reuse_policy,
             ):
                 raise error.Abort(_(b"received dir revlog group is empty"))
 
@@ -2372,6 +2387,7 @@
     needfiles,
     addrevisioncb=None,
     debug_info=None,
+    delta_base_reuse_policy=None,
 ):
     revisions = 0
     files = 0
@@ -2393,6 +2409,7 @@
                 trp,
                 addrevisioncb=addrevisioncb,
                 debug_info=debug_info,
+                delta_base_reuse_policy=delta_base_reuse_policy,
             )
             if not added:
                 raise error.Abort(_(b"received file revlog group is empty"))
--- a/mercurial/filelog.py	Sat Dec 03 01:16:22 2022 +0100
+++ b/mercurial/filelog.py	Sat Dec 03 01:31:23 2022 +0100
@@ -154,6 +154,7 @@
         duplicaterevisioncb=None,
         maybemissingparents=False,
         debug_info=None,
+        delta_base_reuse_policy=None,
     ):
         if maybemissingparents:
             raise error.Abort(
@@ -175,6 +176,7 @@
                 addrevisioncb=addrevisioncb,
                 duplicaterevisioncb=duplicaterevisioncb,
                 debug_info=debug_info,
+                delta_base_reuse_policy=delta_base_reuse_policy,
             )
 
     def getstrippoint(self, minlink):
--- a/mercurial/manifest.py	Sat Dec 03 01:16:22 2022 +0100
+++ b/mercurial/manifest.py	Sat Dec 03 01:31:23 2022 +0100
@@ -1857,6 +1857,7 @@
         addrevisioncb=None,
         duplicaterevisioncb=None,
         debug_info=None,
+        delta_base_reuse_policy=None,
     ):
         return self._revlog.addgroup(
             deltas,
@@ -1866,6 +1867,7 @@
             addrevisioncb=addrevisioncb,
             duplicaterevisioncb=duplicaterevisioncb,
             debug_info=debug_info,
+            delta_base_reuse_policy=delta_base_reuse_policy,
         )
 
     def rawsize(self, rev):
--- a/mercurial/revlog.py	Sat Dec 03 01:16:22 2022 +0100
+++ b/mercurial/revlog.py	Sat Dec 03 01:31:23 2022 +0100
@@ -2663,6 +2663,7 @@
         addrevisioncb=None,
         duplicaterevisioncb=None,
         debug_info=None,
+        delta_base_reuse_policy=None,
     ):
         """
         add a delta group
@@ -2678,6 +2679,14 @@
         if self._adding_group:
             raise error.ProgrammingError(b'cannot nest addgroup() calls')
 
+        # read the default delta-base reuse policy from revlog config if the
+        # group did not specify one.
+        if delta_base_reuse_policy is None:
+            if self._generaldelta and self._lazydeltabase:
+                delta_base_reuse_policy = DELTA_BASE_REUSE_TRY
+            else:
+                delta_base_reuse_policy = DELTA_BASE_REUSE_NO
+
         self._adding_group = True
         empty = True
         try:
@@ -2758,7 +2767,7 @@
                         p1,
                         p2,
                         flags,
-                        (baserev, delta),
+                        (baserev, delta, delta_base_reuse_policy),
                         alwayscache=alwayscache,
                         deltacomputer=deltacomputer,
                         sidedata=sidedata,