revlog: merge hash checking subfunctions
authorRemi Chaintron <remi@fb.com>
Tue, 13 Dec 2016 14:21:36 +0000
changeset 30584 be5b2098a817
parent 30583 8f8211903b83
child 30585 0f865311ae3f
revlog: merge hash checking subfunctions This patch factors the behavior of both methods into 'checkhash'.
contrib/perf.py
mercurial/bundlerepo.py
mercurial/filelog.py
mercurial/revlog.py
--- a/contrib/perf.py	Fri Dec 09 03:22:26 2016 -0800
+++ b/contrib/perf.py	Tue Dec 13 14:21:36 2016 +0000
@@ -999,7 +999,7 @@
     def dohash(text):
         if not cache:
             r.clearcaches()
-        r._checkhash(text, node, rev)
+        r.checkhash(text, node, rev=rev)
 
     def dorevision():
         if not cache:
--- a/mercurial/bundlerepo.py	Fri Dec 09 03:22:26 2016 -0800
+++ b/mercurial/bundlerepo.py	Tue Dec 13 14:21:36 2016 +0000
@@ -148,7 +148,7 @@
             delta = self._chunk(chain.pop())
             text = mdiff.patches(text, [delta])
 
-        self._checkhash(text, node, rev)
+        self.checkhash(text, node, rev=rev)
         self._cache = (node, rev, text)
         return text
 
--- a/mercurial/filelog.py	Fri Dec 09 03:22:26 2016 -0800
+++ b/mercurial/filelog.py	Tue Dec 13 14:21:36 2016 +0000
@@ -104,9 +104,9 @@
 
         return True
 
-    def checkhash(self, text, p1, p2, node, rev=None):
+    def checkhash(self, text, node, p1=None, p2=None, rev=None):
         try:
-            super(filelog, self).checkhash(text, p1, p2, node, rev=rev)
+            super(filelog, self).checkhash(text, node, p1=p1, p2=p2, rev=rev)
         except error.RevlogError:
             if _censoredtext(text):
                 raise error.CensoredNodeError(self.indexfile, node, text)
--- a/mercurial/revlog.py	Fri Dec 09 03:22:26 2016 -0800
+++ b/mercurial/revlog.py	Tue Dec 13 14:21:36 2016 +0000
@@ -1247,9 +1247,7 @@
             bins = bins[1:]
 
         text = mdiff.patches(text, bins)
-
-        text = self._checkhash(text, node, rev)
-
+        self.checkhash(text, node, rev=rev)
         self._cache = (node, rev, text)
         return text
 
@@ -1261,12 +1259,14 @@
         """
         return hash(text, p1, p2)
 
-    def _checkhash(self, text, node, rev):
-        p1, p2 = self.parents(node)
-        self.checkhash(text, p1, p2, node, rev)
-        return text
+    def checkhash(self, text, node, p1=None, p2=None, rev=None):
+        """Check node hash integrity.
 
-    def checkhash(self, text, p1, p2, node, rev=None):
+        Available as a function so that subclasses can extend hash mismatch
+        behaviors as needed.
+        """
+        if p1 is None and p2 is None:
+            p1, p2 = self.parents(node)
         if node != self.hash(text, p1, p2):
             revornode = rev
             if revornode is None:
@@ -1441,7 +1441,7 @@
                 basetext = self.revision(self.node(baserev), _df=fh)
                 btext[0] = mdiff.patch(basetext, delta)
             try:
-                self.checkhash(btext[0], p1, p2, node)
+                self.checkhash(btext[0], node, p1=p1, p2=p2)
                 if flags & REVIDX_ISCENSORED:
                     raise RevlogError(_('node %s is not censored') % node)
             except CensoredNodeError: