changeset 98:3dde7c87e36d

Add paranoia to diff code
author mpm@selenic.com
date Wed, 18 May 2005 16:59:54 -0800
parents 7a2abee6b0c2
children 58039eddbdda
files mercurial/hg.py mercurial/revlog.py
diffstat 2 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Wed May 18 16:47:49 2005 -0800
+++ b/mercurial/hg.py	Wed May 18 16:59:54 2005 -0800
@@ -78,7 +78,11 @@
     def diff(self, a, b):
         # this is sneaky, as we're not actually using a and b
         if self.listcache and len(self.listcache[0]) == len(a):
-            return mdiff.diff(self.listcache[1], self.addlist, 1)
+            d = mdiff.diff(self.listcache[1], self.addlist, 1)
+            if mdiff.patch(a, d) != b:
+                sys.stderr.write("*** sortdiff failed, falling back ***\n")
+                return mdiff.textdiff(a, b)
+            return d
         else:
             return mdiff.textdiff(a, b)
 
--- a/mercurial/revlog.py	Wed May 18 16:47:49 2005 -0800
+++ b/mercurial/revlog.py	Wed May 18 16:59:54 2005 -0800
@@ -190,7 +190,8 @@
 
         (p1, p2) = self.parents(node)
         if node != hash(text, p1, p2):
-            raise "integrity check failed on %s:%d" % (self.datafile, rev)
+            raise IOError("integrity check failed on %s:%d"
+                          % (self.datafile, rev))
 
         self.cache = (node, rev, text)
         return text  
@@ -210,7 +211,10 @@
             start = self.start(base)
             end = self.end(t)
             prev = self.revision(self.tip())
-            data = compress(self.diff(prev, text))
+            d = self.diff(prev, text)
+            if self.patches(prev, [d]) != text:
+                raise AssertionError("diff failed")
+            data = compress(d)
             dist = end - start + len(data)
 
         # full versions are inserted when the needed deltas