changeset 51097:be56d322ee89

revlog: move the `rawtext` method on the inner object This is one of the current core goal of the inner object: having a "simple" API for some of the core revlog action, like getting a raw text, with the inner object able to do that part internally, on its own.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 19 Oct 2023 03:52:31 +0200
parents 8ec2de9c6770
children 49d75cc12b8f
files mercurial/revlog.py
diffstat 1 files changed, 54 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Thu Oct 19 03:33:59 2023 +0200
+++ b/mercurial/revlog.py	Thu Oct 19 03:52:31 2023 +0200
@@ -900,6 +900,44 @@
 
         return l
 
+    def raw_text(self, node, rev):
+        """return the possibly unvalidated rawtext for a revision
+
+        returns (rev, rawtext, validated)
+        """
+
+        # revision in the cache (could be useful to apply delta)
+        cachedrev = None
+        # An intermediate text to apply deltas to
+        basetext = None
+
+        # Check if we have the entry in cache
+        # The cache entry looks like (node, rev, rawtext)
+        if self._revisioncache:
+            cachedrev = self._revisioncache[1]
+
+        chain, stopped = self._deltachain(rev, stoprev=cachedrev)
+        if stopped:
+            basetext = self._revisioncache[2]
+
+        # drop cache to save memory, the caller is expected to
+        # update self._inner._revisioncache after validating the text
+        self._revisioncache = None
+
+        targetsize = None
+        rawsize = self.index[rev][2]
+        if 0 <= rawsize:
+            targetsize = 4 * rawsize
+
+        bins = self._chunks(chain, targetsize=targetsize)
+        if basetext is None:
+            basetext = bytes(bins[0])
+            bins = bins[1:]
+
+        rawtext = mdiff.patches(basetext, bins)
+        del basetext  # let us have a chance to free memory early
+        return (rev, rawtext, False)
+
 
 class revlog:
     """
@@ -2531,6 +2569,22 @@
             rev = self.rev(nodeorrev)
         return self._sidedata(rev)
 
+    def _rawtext(self, node, rev):
+        """return the possibly unvalidated rawtext for a revision
+
+        returns (rev, rawtext, validated)
+        """
+        # Check if we have the entry in cache
+        # The cache entry looks like (node, rev, rawtext)
+        if self._inner._revisioncache:
+            if self._inner._revisioncache[0] == node:
+                return (rev, self._inner._revisioncache[2], True)
+
+        if rev is None:
+            rev = self.rev(node)
+
+        return self._inner.raw_text(node, rev)
+
     def _revisiondata(self, nodeorrev, raw=False):
         # deal with <nodeorrev> argument type
         if isinstance(nodeorrev, int):
@@ -2575,49 +2629,6 @@
 
         return text
 
-    def _rawtext(self, node, rev):
-        """return the possibly unvalidated rawtext for a revision
-
-        returns (rev, rawtext, validated)
-        """
-
-        # revision in the cache (could be useful to apply delta)
-        cachedrev = None
-        # An intermediate text to apply deltas to
-        basetext = None
-
-        # Check if we have the entry in cache
-        # The cache entry looks like (node, rev, rawtext)
-        if self._inner._revisioncache:
-            if self._inner._revisioncache[0] == node:
-                return (rev, self._inner._revisioncache[2], True)
-            cachedrev = self._inner._revisioncache[1]
-
-        if rev is None:
-            rev = self.rev(node)
-
-        chain, stopped = self._inner._deltachain(rev, stoprev=cachedrev)
-        if stopped:
-            basetext = self._inner._revisioncache[2]
-
-        # drop cache to save memory, the caller is expected to
-        # update self._inner._revisioncache after validating the text
-        self._inner._revisioncache = None
-
-        targetsize = None
-        rawsize = self.index[rev][2]
-        if 0 <= rawsize:
-            targetsize = 4 * rawsize
-
-        bins = self._inner._chunks(chain, targetsize=targetsize)
-        if basetext is None:
-            basetext = bytes(bins[0])
-            bins = bins[1:]
-
-        rawtext = mdiff.patches(basetext, bins)
-        del basetext  # let us have a chance to free memory early
-        return (rev, rawtext, False)
-
     def _sidedata(self, rev):
         """Return the sidedata for a given revision number."""
         index_entry = self.index[rev]