[PATCH 3 of 6] revlog: add support for 'original text' to addrevision and addgroup

Matt Mackall mpm at selenic.com
Mon Jan 31 17:43:36 CST 2011


On Mon, 2011-01-31 at 11:21 +0100, Sune Foldager wrote:
> # HG changeset patch
> # User Sune Foldager <cryo at cyanite.org>
> # Date 1284635515 -7200
> # Node ID c53628efd882402813e98fc86bde1bf825ad1c79
> # Parent  228f2570b1922c797b969dab28a28e3f1ec99cf7
> revlog: add support for 'original text' to addrevision and addgroup
> 
> This allows derived revlogs to store a different text from the one accepted and
> returned via the API. This can be used for custom compressed entries, such as
> for light-weight copy.
> 
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -923,7 +923,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,
> +                    origtext=None):

I think this is not the ideal interface. 

This appears to be motivated by the need to calculate the hash based on
the known text. But wouldn't it be better to factor out hash calculation
(already done!), then have filelog pass the hash in?

diff -r d119403fd266 mercurial/revlog.py
--- a/mercurial/revlog.py	Fri Jan 28 17:02:29 2011 -0600
+++ b/mercurial/revlog.py	Mon Jan 31 17:40:27 2011 -0600
@@ -921,7 +921,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
@@ -930,7 +931,10 @@
         p1, p2 - the parent nodeids of the revision
         cachedelta - an optional precomputed delta
         """
-        node = hash(text, p1, p2)
+
+        if node is None:
+            node = hash(text, p1, p2)
+
         if (node in self.nodemap and
             (not self.flags(self.rev(node)) & REVIDX_PUNCHED_FLAG)):
             return node


This has other benefits. For instance, in the wire protocol, we already
know the hash of deltas we're adding and can thus avoid recalculating
them.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list