changeset 51096:9c8df10ea6e0

revlog: move the `_chunk` 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 02:57:05 +0200
parents a82704902db8
children ff673b9da21f
files contrib/perf.py mercurial/revlog.py mercurial/revlogutils/rewrite.py
diffstat 3 files changed, 30 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Wed Oct 25 02:13:18 2023 +0200
+++ b/contrib/perf.py	Thu Oct 19 02:57:05 2023 +0200
@@ -3810,13 +3810,15 @@
 
     def dochunk():
         rl.clearcaches()
+        # chunk used to be available directly on the revlog
+        _chunk = getattr(rl, '_inner', rl)._chunk
         with reading(rl) as fh:
             if fh is not None:
                 for rev in revs:
-                    rl._chunk(rev, df=fh)
+                    _chunk(rev, df=fh)
             else:
                 for rev in revs:
-                    rl._chunk(rev)
+                    _chunk(rev)
 
     chunks = [None]
 
--- a/mercurial/revlog.py	Wed Oct 25 02:13:18 2023 +0200
+++ b/mercurial/revlog.py	Thu Oct 19 02:57:05 2023 +0200
@@ -718,6 +718,28 @@
 
         return start, self._segmentfile.read_chunk(start, length)
 
+    def _chunk(self, rev):
+        """Obtain a single decompressed chunk for a revision.
+
+        Accepts an integer revision and an optional already-open file handle
+        to be used for reading. If used, the seek position of the file will not
+        be preserved.
+
+        Returns a str holding uncompressed data for the requested revision.
+        """
+        compression_mode = self.index[rev][10]
+        data = self.get_segment_for_revs(rev, rev)[1]
+        if compression_mode == COMP_MODE_PLAIN:
+            return data
+        elif compression_mode == COMP_MODE_DEFAULT:
+            return self._decompressor(data)
+        elif compression_mode == COMP_MODE_INLINE:
+            return self.decompress(data)
+        else:
+            msg = b'unknown compression mode %d'
+            msg %= compression_mode
+            raise error.RevlogError(msg)
+
 
 class revlog:
     """
@@ -2336,28 +2358,6 @@
         p1, p2 = self.parents(node)
         return storageutil.hashrevisionsha1(text, p1, p2) != node
 
-    def _chunk(self, rev):
-        """Obtain a single decompressed chunk for a revision.
-
-        Accepts an integer revision and an optional already-open file handle
-        to be used for reading. If used, the seek position of the file will not
-        be preserved.
-
-        Returns a str holding uncompressed data for the requested revision.
-        """
-        compression_mode = self.index[rev][10]
-        data = self._inner.get_segment_for_revs(rev, rev)[1]
-        if compression_mode == COMP_MODE_PLAIN:
-            return data
-        elif compression_mode == COMP_MODE_DEFAULT:
-            return self._inner._decompressor(data)
-        elif compression_mode == COMP_MODE_INLINE:
-            return self._inner.decompress(data)
-        else:
-            msg = b'unknown compression mode %d'
-            msg %= compression_mode
-            raise error.RevlogError(msg)
-
     def _chunks(self, revs, targetsize=None):
         """Obtain decompressed chunks for the specified revisions.
 
@@ -2404,7 +2404,7 @@
             except OverflowError:
                 # issue4215 - we can't cache a run of chunks greater than
                 # 2G on Windows
-                return [self._chunk(rev) for rev in revschunk]
+                return [self._inner._chunk(rev) for rev in revschunk]
 
             decomp = self._inner.decompress
             # self._decompressor might be None, but will not be used in that case
@@ -2484,7 +2484,7 @@
         revlog data directly. So this function needs raw revision data.
         """
         if rev1 != nullrev and self.deltaparent(rev2) == rev1:
-            return bytes(self._chunk(rev2))
+            return bytes(self._inner._chunk(rev2))
 
         return mdiff.textdiff(self.rawdata(rev1), self.rawdata(rev2))
 
@@ -3681,7 +3681,7 @@
                 if destrevlog.delta_config.lazy_delta:
                     dp = self.deltaparent(rev)
                     if dp != nullrev:
-                        cachedelta = (dp, bytes(self._chunk(rev)))
+                        cachedelta = (dp, bytes(self._inner._chunk(rev)))
 
                 sidedata = None
                 if not cachedelta:
--- a/mercurial/revlogutils/rewrite.py	Wed Oct 25 02:13:18 2023 +0200
+++ b/mercurial/revlogutils/rewrite.py	Thu Oct 19 02:57:05 2023 +0200
@@ -109,7 +109,7 @@
                     b'revision having delta stored'
                 )
                 raise error.Abort(m)
-            rawtext = rl._chunk(rev)
+            rawtext = rl._inner._chunk(rev)
         else:
             rawtext = rl.rawdata(rev)