changeset 5312:fb070713ff36

revlog: more robust for damaged indexes - fix flag reporting - make broken length reporting smarter
author Matt Mackall <mpm@selenic.com>
date Fri, 21 Sep 2007 17:14:39 -0500
parents 599f3a690d8f
children 29be4228303b
files mercurial/revlog.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Fri Sep 21 17:13:38 2007 -0500
+++ b/mercurial/revlog.py	Fri Sep 21 17:14:39 2007 -0500
@@ -912,7 +912,8 @@
 
         # check rev flags
         if self.index[rev][0] & 0xFFFF:
-            raise RevlogError(_('incompatible revision flag %x') % q)
+            raise RevlogError(_('incompatible revision flag %x') %
+                              (self.index[rev][0] & 0xFFFF))
 
         if self._inline:
             # we probably have the whole chunk cached
@@ -1236,7 +1237,7 @@
     def checksize(self):
         expected = 0
         if self.count():
-            expected = self.end(self.count() - 1)
+            expected = max(0, self.end(self.count() - 1))
 
         try:
             f = self.opener(self.datafile)
@@ -1253,12 +1254,12 @@
             f.seek(0, 2)
             actual = f.tell()
             s = self._io.size
-            i = actual / s
+            i = max(0, actual / s)
             di = actual - (i * s)
             if self._inline:
                 databytes = 0
                 for r in xrange(self.count()):
-                    databytes += self.length(r)
+                    databytes += max(0, self.length(r))
                 dd = 0
                 di = actual - self.count() * s - databytes
         except IOError, inst: