changeset 51095:30f458fc59e9

revlog: move the `deltachain` method on the inner object This is a necessary step before being able to move more logic around restoring a revision content there. For now, we do a simple patch for the perf extension logic, when the implementation of the inner object changes, we will likely need some evolution of the API. However this is true of many things in the perf extension. So we will see this later.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 19 Oct 2023 03:07:39 +0200
parents e8ad6d8de8b8
children 8ec2de9c6770
files mercurial/revlog.py
diffstat 1 files changed, 44 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Thu Oct 19 03:00:58 2023 +0200
+++ b/mercurial/revlog.py	Thu Oct 19 03:07:39 2023 +0200
@@ -460,6 +460,47 @@
             return False
         return self.issnapshot(base)
 
+    def _deltachain(self, rev, stoprev=None):
+        """Obtain the delta chain for a revision.
+
+        ``stoprev`` specifies a revision to stop at. If not specified, we
+        stop at the base of the chain.
+
+        Returns a 2-tuple of (chain, stopped) where ``chain`` is a list of
+        revs in ascending order and ``stopped`` is a bool indicating whether
+        ``stoprev`` was hit.
+        """
+        generaldelta = self.delta_config.general_delta
+        # Try C implementation.
+        try:
+            return self.index.deltachain(rev, stoprev, generaldelta)
+        except AttributeError:
+            pass
+
+        chain = []
+
+        # Alias to prevent attribute lookup in tight loop.
+        index = self.index
+
+        iterrev = rev
+        e = index[iterrev]
+        while iterrev != e[3] and iterrev != stoprev:
+            chain.append(iterrev)
+            if generaldelta:
+                iterrev = e[3]
+            else:
+                iterrev -= 1
+            e = index[iterrev]
+
+        if iterrev == stoprev:
+            stopped = True
+        else:
+            chain.append(iterrev)
+            stopped = False
+
+        chain.reverse()
+        return chain, stopped
+
     @util.propertycache
     def _compressor(self):
         engine = util.compengines[self.feature_config.compression_engine]
@@ -1003,7 +1044,6 @@
 
         chunk_cache = self._loadindex()
         self._load_inner(chunk_cache)
-
         self._concurrencychecker = concurrencychecker
 
     @property
@@ -1823,45 +1863,7 @@
         return r
 
     def _deltachain(self, rev, stoprev=None):
-        """Obtain the delta chain for a revision.
-
-        ``stoprev`` specifies a revision to stop at. If not specified, we
-        stop at the base of the chain.
-
-        Returns a 2-tuple of (chain, stopped) where ``chain`` is a list of
-        revs in ascending order and ``stopped`` is a bool indicating whether
-        ``stoprev`` was hit.
-        """
-        generaldelta = self.delta_config.general_delta
-        # Try C implementation.
-        try:
-            return self.index.deltachain(rev, stoprev, generaldelta)
-        except AttributeError:
-            pass
-
-        chain = []
-
-        # Alias to prevent attribute lookup in tight loop.
-        index = self.index
-
-        iterrev = rev
-        e = index[iterrev]
-        while iterrev != e[3] and iterrev != stoprev:
-            chain.append(iterrev)
-            if generaldelta:
-                iterrev = e[3]
-            else:
-                iterrev -= 1
-            e = index[iterrev]
-
-        if iterrev == stoprev:
-            stopped = True
-        else:
-            chain.append(iterrev)
-            stopped = False
-
-        chain.reverse()
-        return chain, stopped
+        return self._inner._deltachain(rev, stoprev=stoprev)
 
     def ancestors(self, revs, stoprev=0, inclusive=False):
         """Generate the ancestors of 'revs' in reverse revision order.
@@ -2496,7 +2498,7 @@
         """number of snapshot in the chain before this one"""
         if not self.issnapshot(rev):
             raise error.ProgrammingError(b'revision %d not a snapshot')
-        return len(self._deltachain(rev)[0]) - 1
+        return len(self._inner._deltachain(rev)[0]) - 1
 
     def revdiff(self, rev1, rev2):
         """return or calculate a delta between two revisions
@@ -2594,7 +2596,7 @@
         if rev is None:
             rev = self.rev(node)
 
-        chain, stopped = self._deltachain(rev, stoprev=cachedrev)
+        chain, stopped = self._inner._deltachain(rev, stoprev=cachedrev)
         if stopped:
             basetext = self._revisioncache[2]