changeset 1667:daff3ef0de8d

verify: notice extra data in indices
author Matt Mackall <mpm@selenic.com>
date Mon, 30 Jan 2006 19:34:35 +1300
parents 0fc1b588976f
children 586b50294ea8 91d40fc959f0 dee55c4a4963 dd5085897010 4b1e0dc913bf 93f54a2b3864
files mercurial/localrepo.py mercurial/revlog.py
diffstat 2 files changed, 32 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Mon Jan 30 13:01:16 2006 +1300
+++ b/mercurial/localrepo.py	Mon Jan 30 19:34:35 2006 +1300
@@ -1679,11 +1679,17 @@
             self.ui.warn(msg + "\n")
             errors[0] += 1
 
+        def checksize(obj, name):
+            d = obj.checksize()
+            if d[0]:
+                err(_("%s data length off by %d bytes") % (name, d[0]))
+            if d[1]:
+                err(_("%s index contains %d extra bytes") % (name, d[1]))
+
         seen = {}
         self.ui.status(_("checking changesets\n"))
-        d = self.changelog.checksize()
-        if d:
-            err(_("changeset data short %d bytes") % d)
+        checksize(self.changelog, "changelog")
+
         for i in range(self.changelog.count()):
             changesets += 1
             n = self.changelog.node(i)
@@ -1713,9 +1719,8 @@
 
         seen = {}
         self.ui.status(_("checking manifests\n"))
-        d = self.manifest.checksize()
-        if d:
-            err(_("manifest data short %d bytes") % d)
+        checksize(self.manifest, "manifest")
+
         for i in range(self.manifest.count()):
             n = self.manifest.node(i)
             l = self.manifest.linkrev(n)
@@ -1771,9 +1776,7 @@
                 continue
             files += 1
             fl = self.file(f)
-            d = fl.checksize()
-            if d:
-                err(_("%s file data short %d bytes") % (f, d))
+            checksize(fl, f)
 
             nodes = {nullid: 1}
             seen = {}
--- a/mercurial/revlog.py	Mon Jan 30 13:01:16 2006 +1300
+++ b/mercurial/revlog.py	Mon Jan 30 19:34:35 2006 +1300
@@ -213,7 +213,7 @@
             m = [None] * l
 
             n = 0
-            for f in xrange(0, len(i), s):
+            for f in xrange(0, l * s, s):
                 # offset, size, base, linkrev, p1, p2, nodeid
                 e = struct.unpack(indexformat, i[f:f + s])
                 m[n] = (e[6], n)
@@ -841,14 +841,29 @@
         expected = 0
         if self.count():
             expected = self.end(self.count() - 1)
+
         try:
             f = self.opener(self.datafile)
             f.seek(0, 2)
             actual = f.tell()
-            return expected - actual
+            dd = actual - expected
         except IOError, inst:
-            if inst.errno == errno.ENOENT:
-                return 0
-            raise
+            if inst.errno != errno.ENOENT:
+                raise
+            dd = 0
+
+        try:
+            f = self.opener(self.indexfile)
+            f.seek(0, 2)
+            actual = f.tell()
+            s = struct.calcsize(indexformat)
+            i = actual / s
+            di = actual - (i * s)
+        except IOError, inst:
+            if inst.errno != errno.ENOENT:
+                raise
+            di = 0
+
+        return (dd, di)