Patchwork [1,of,2] revlog: extract 'checkhash' method

login
register
mail settings
Submitter Wojciech Lopata
Date Aug. 19, 2013, 7:46 p.m.
Message ID <89b4d30ddd5c1d09c61d.1376941571@dev1179.prn1.facebook.com>
Download mbox | patch
Permalink /patch/2228/
State Superseded
Commit 55749cb14d248eb8c231767be0709d7ed4d7801c
Headers show

Comments

Wojciech Lopata - Aug. 19, 2013, 7:46 p.m.
# HG changeset patch
# User Wojciech Lopata <lopek@fb.com>
# Date 1376935598 25200
#      Mon Aug 19 11:06:38 2013 -0700
# Node ID 89b4d30ddd5c1d09c61d4578b1ad4875b7780418
# Parent  6ac206fb6f27492a98f46bbff090407ee1b1de72
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.
Augie Fackler - Aug. 26, 2013, 1:56 p.m.
On Mon, Aug 19, 2013 at 12:46:11PM -0700, Wojciech Lopata wrote:
> # HG changeset patch
> # User Wojciech Lopata <lopek@fb.com>
> # Date 1376935598 25200
> #      Mon Aug 19 11:06:38 2013 -0700
> # Node ID 89b4d30ddd5c1d09c61d4578b1ad4875b7780418
> # Parent  6ac206fb6f27492a98f46bbff090407ee1b1de72
> 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.

commit message wants to mention the immediate consumer of this. I'm
guessing that it has to do with manifest compression, but it'd be nice
to state that intent here for those following along at home.

>
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -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,14 @@
>
>      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 or 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 +1067,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):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -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,14 @@ 
 
     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 or 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 +1067,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):