[PATCH 2 of 5 manifest-cleanup] revlog: move references to revlog.hash to inside the revlog class

Augie Fackler raf at durin42.com
Wed Oct 8 12:06:50 CDT 2014

# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1411586084 14400
#      Wed Sep 24 15:14:44 2014 -0400
# Node ID ff79cf931d0105e1749e6edfd309d7ed303155b8
# Parent  9f8980f8de75b63b27d92780ef504cef1f9c9b0f
revlog: move references to revlog.hash to inside the revlog class

This will make it possible for subclasses to have different hashing
schemes when appropriate. I anticipate using this in manifests.

Note that there's still one client of mercurial.revlog.hash() outside
of revlog: mercurial.context.memctx uses it to construct the file
entries in an in-memory manifest. I don't think this will be a problem
in the immediate future, so I've left it as-is.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1036,13 +1036,21 @@
         self._cache = (node, rev, text)
         return text
+    def hash(self, text, p1, p2):
+        """Compute a node hash.
+        Available as a function so that subclasses can replace the hash
+        as needed.
+        """
+        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, p1, p2, node, rev=None):
-        if node != hash(text, p1, p2):
+        if node != self.hash(text, p1, p2):
             revornode = rev
             if revornode is None:
                 revornode = templatefilters.short(hex(node))
@@ -1104,7 +1112,7 @@
         if link == nullrev:
             raise RevlogError(_("attempted to add linkrev -1 to %s")
                               % self.indexfile)
-        node = node or hash(text, p1, p2)
+        node = node or self.hash(text, p1, p2)
         if node in self.nodemap:
             return node

More information about the Mercurial-devel mailing list