[PATCH 1 of 1] revlog: fix for generaldelta distance calculation

Friedrich Kastner-Masilko kastner_masilko at at.festo.com
Wed Jul 11 05:54:13 CDT 2012


# HG changeset patch
# User Friedrich Kastner-Masilko <kastner_masilko at at.festo.com>
# Date 1342003122 -7200
# Branch stable
# Node ID eceb11ca1474223b22298be9b95fd26cbd09c06b
# Parent  195dbd1cef0c2f9f8bcf4ea303238105f716bda3
revlog: fix for generaldelta distance calculation

The decision whether or not to store a full snapshot instead of a delta is done
based on the distance value calculated in _addrevision.builddelta(rev).

This calculation traditionally used the fact of deltas only using the previous
revision as base. Generaldelta mechanism is changing this, yet the calculation
still assumes that current-offset minus chainbase-offset equals chain-length.
This appears to be wrong.

This patch corrects the calculation by means of using the chainlength function
if Generaldelta is used.

diff -r 195dbd1cef0c -r eceb11ca1474 mercurial/revlog.py
--- a/mercurial/revlog.py	Thu Dec 01 15:51:36 2011 -0600
+++ b/mercurial/revlog.py	Wed Jul 11 12:38:42 2012 +0200
@@ -328,6 +328,15 @@
             rev = base
             base = index[rev][3]
         return base
+    def chainlength(self, rev):
+        index = self.index
+        base = index[rev][3]
+        length = index[rev][1]
+        while base != rev:            
+            rev = base
+            base = index[rev][3]
+            length = length + index[rev][1]
+        return length
     def flags(self, rev):
         return self.index[rev][0] & 0xFFFF
     def rawsize(self, rev):
@@ -1016,11 +1025,12 @@
             if basecache[0] == rev:
                 chainbase = basecache[1]
             else:
-                chainbase = self.chainbase(rev)
-            dist = l + offset - self.start(chainbase)
+                chainbase = self.chainbase(rev)            
             if self._generaldelta:
+                dist = l + self.chainlength(rev)
                 base = rev
             else:
+                dist = l + offset - self.start(chainbase)
                 base = chainbase
             return dist, l, data, base, chainbase
 


More information about the Mercurial-devel mailing list