Patchwork [2,of,2] revlog: pass node as an argument of addrevision

login
register
mail settings
Submitter Wojciech Lopata
Date Aug. 26, 2013, 4:42 p.m.
Message ID <1c7cf12674ecf5a8561a.1377535372@dev1179.prn1.facebook.com>
Download mbox | patch
Permalink /patch/2263/
State Accepted
Headers show

Comments

Wojciech Lopata - Aug. 26, 2013, 4:42 p.m.
# HG changeset patch
# User Wojciech Lopata <lopek@fb.com>
# Date 1376936723 25200
#      Mon Aug 19 11:25:23 2013 -0700
# Node ID 1c7cf12674ecf5a8561a94cf93828ace0cd63027
# Parent  59ee8426d8064e4efb4bf961fdb060769ae1b308
revlog: pass node as an argument of addrevision

This change will allow revlog subclasses that override 'checkhash' method
to use custom strategy of computing nodeids without overriding 'addrevision'
method. In particular this change is necessary to implement manifest
compression.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -993,7 +993,8 @@ 
         tr.replace(self.indexfile, trindex * self._io.size)
         self._chunkclear()
 
-    def addrevision(self, text, transaction, link, p1, p2, cachedelta=None):
+    def addrevision(self, text, transaction, link, p1, p2, cachedelta=None,
+                    node=None):
         """add a revision to the log
 
         text - the revision data to add
@@ -1001,11 +1002,14 @@ 
         link - the linkrev data to add
         p1, p2 - the parent nodeids of the revision
         cachedelta - an optional precomputed delta
+        node - nodeid of revision; typically node is not specified, and it is
+            computed by default as hash(text, p1, p2), however subclasses might
+            use different hashing method (and override checkhash() in such case)
         """
         if link == nullrev:
             raise RevlogError(_("attempted to add linkrev -1 to %s")
                               % self.indexfile)
-        node = hash(text, p1, p2)
+        node = node or hash(text, p1, p2)
         if node in self.nodemap:
             return node