[PATCH 1 of 9] bundlerepo: simplify code to take advantage of `_rawtext`

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Aug 30 12:39:30 EDT 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1567170294 -7200
#      Fri Aug 30 15:04:54 2019 +0200
# Node ID 151b3d3e5176e4f9f4ab1b68756f4ba73dfcf7c4
# Parent  2c4f656c8e9f61afd8590d6daf59d5593eeaa29c
# EXP-Topic sidedata-prep
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 151b3d3e5176
bundlerepo: simplify code to take advantage of `_rawtext`

In the revlog code, the code getting the raw text is now isolated. We take
advantage of this to simplify the bundlerepo code.


update bundlerepo code

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -17,7 +17,10 @@ import os
 import shutil
 
 from .i18n import _
-from .node import nullid
+from .node import (
+    nullid,
+    nullrev
+)
 
 from . import (
     bundle2,
@@ -108,20 +111,10 @@ class bundlerevlog(revlog.revlog):
         return mdiff.textdiff(self.rawdata(rev1),
                               self.rawdata(rev2))
 
-    def revision(self, nodeorrev, _df=None, raw=False):
-        """return an uncompressed revision of a given node or revision
-        number.
-        """
-        if isinstance(nodeorrev, int):
-            rev = nodeorrev
-            node = self.node(rev)
-        else:
-            node = nodeorrev
+    def _rawtext(self, node, rev, _df=None):
+        if rev is None:
             rev = self.rev(node)
-
-        if node == nullid:
-            return ""
-
+        validated = False
         rawtext = None
         chain = []
         iterrev = rev
@@ -132,19 +125,19 @@ class bundlerevlog(revlog.revlog):
                 break
             chain.append(iterrev)
             iterrev = self.index[iterrev][3]
-        if rawtext is None:
-            rawtext = self.baserevision(iterrev)
-
+        if iterrev == nullrev:
+            rawtext = ''
+        elif rawtext is None:
+            r = super(bundlerevlog, self)._rawtext(self.node(iterrev),
+                                                   iterrev,
+                                                   _df=_df)
+            __, rawtext, validated = r
+        if chain:
+            validated = False
         while chain:
             delta = self._chunk(chain.pop())
             rawtext = mdiff.patches(rawtext, [delta])
-
-        text, validatehash = self._processflags(rawtext, self.flags(rev),
-                                                'read', raw=raw)
-        if validatehash:
-            self.checkhash(text, node, rev=rev)
-        self._revisioncache = (node, rev, rawtext)
-        return text
+        return rev, rawtext, validated
 
     def rawdata(self, nodeorrev, _df=None):
         return self.revision(nodeorrev, _df=_df, raw=True)


More information about the Mercurial-devel mailing list