changeset 19624:55749cb14d24

revlog: extract 'checkhash' method Extract method that decides whether nodeid is correct for paricular revision text and parent nodes. Having this method extracted will allow revlog subclasses to implement custom way of computing nodes. In particular this change is necessary to implement manifest compression.
author Wojciech Lopata <lopek@fb.com>
date Mon, 19 Aug 2013 11:06:38 -0700
parents d0dbe5330177
children 6a411a06cb1f
files mercurial/revlog.py
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Mon Aug 26 16:11:21 2013 +0900
+++ b/mercurial/revlog.py	Mon Aug 19 11:06:38 2013 -0700
@@ -14,7 +14,7 @@
 # import stuff from node for others to import from revlog
 from node import bin, hex, nullid, nullrev
 from i18n import _
-import ancestor, mdiff, parsers, error, util
+import ancestor, mdiff, parsers, error, util, templatefilters
 import struct, zlib, errno
 
 _pack = struct.pack
@@ -943,10 +943,16 @@
 
     def _checkhash(self, text, node, rev):
         p1, p2 = self.parents(node)
+        self.checkhash(text, p1, p2, node, rev)
+        return text
+
+    def checkhash(self, text, p1, p2, node, rev=None):
         if node != hash(text, p1, p2):
-            raise RevlogError(_("integrity check failed on %s:%d")
-                              % (self.indexfile, rev))
-        return text
+            revornode = rev
+            if revornode is None:
+                revornode = templatefilters.short(hex(node))
+            raise RevlogError(_("integrity check failed on %s:%s")
+                % (self.indexfile, revornode))
 
     def checkinlinesize(self, tr, fp=None):
         if not self._inline or (self.start(-2) + self.length(-2)) < _maxinline:
@@ -1063,9 +1069,7 @@
             ifh.flush()
             basetext = self.revision(self.node(cachedelta[0]))
             btext[0] = mdiff.patch(basetext, cachedelta[1])
-            chk = hash(btext[0], p1, p2)
-            if chk != node:
-                raise RevlogError(_("consistency error in delta"))
+            self.checkhash(btext[0], p1, p2, node)
             return btext[0]
 
         def builddelta(rev):