##// END OF EJS Templates
c0bd7d8b69ef uses err() instead of warn() but prototype doesn't match...
Benoit Boissinot -
r7004:90227c42 default
parent child Browse files
Show More
@@ -1,235 +1,235 b''
1 1 # verify.py - repository integrity checking for Mercurial
2 2 #
3 3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from node import nullid, short
9 9 from i18n import _
10 10 import revlog, util
11 11
12 12 def verify(repo):
13 13 lock = repo.lock()
14 14 try:
15 15 return _verify(repo)
16 16 finally:
17 17 del lock
18 18
19 19 def _verify(repo):
20 20 mflinkrevs = {}
21 21 filelinkrevs = {}
22 22 filenodes = {}
23 23 revisions = 0
24 24 badrevs = {}
25 25 errors = [0]
26 26 warnings = [0]
27 27 ui = repo.ui
28 28 cl = repo.changelog
29 29 mf = repo.manifest
30 30
31 31 def err(linkrev, msg, filename=None):
32 32 if linkrev != None:
33 33 badrevs[linkrev] = True
34 34 else:
35 35 linkrev = '?'
36 36 msg = "%s: %s" % (linkrev, msg)
37 37 if filename:
38 38 msg = "%s@%s" % (filename, msg)
39 39 ui.warn(" " + msg + "\n")
40 40 errors[0] += 1
41 41
42 42 def exc(linkrev, msg, inst, filename=None):
43 43 if isinstance(inst, KeyboardInterrupt):
44 44 ui.warn(_("interrupted"))
45 45 raise
46 46 err(linkrev, "%s: %s" % (msg, inst), filename)
47 47
48 48 def warn(msg):
49 49 ui.warn(msg + "\n")
50 50 warnings[0] += 1
51 51
52 52 def checklog(obj, name):
53 53 if not len(obj) and (havecl or havemf):
54 54 err(0, _("empty or missing %s") % name)
55 55 return
56 56
57 57 d = obj.checksize()
58 58 if d[0]:
59 59 err(None, _("data length off by %d bytes") % d[0], name)
60 60 if d[1]:
61 61 err(None, _("index contains %d extra bytes") % d[1], name)
62 62
63 63 if obj.version != revlog.REVLOGV0:
64 64 if not revlogv1:
65 65 warn(_("warning: `%s' uses revlog format 1") % name)
66 66 elif revlogv1:
67 67 warn(_("warning: `%s' uses revlog format 0") % name)
68 68
69 69 def checkentry(obj, i, node, seen, linkrevs, f):
70 70 lr = obj.linkrev(node)
71 71 if lr < 0 or (havecl and lr not in linkrevs):
72 72 t = "unexpected"
73 73 if lr < 0 or lr >= len(cl):
74 74 t = "nonexistent"
75 75 err(None, _("rev %d point to %s changeset %d") % (i, t, lr), f)
76 76 if linkrevs:
77 77 warn(_(" (expected %s)") % " ".join(map(str,linkrevs)))
78 78 lr = None # can't be trusted
79 79
80 80 try:
81 81 p1, p2 = obj.parents(node)
82 82 if p1 not in seen and p1 != nullid:
83 83 err(lr, _("unknown parent 1 %s of %s") %
84 84 (short(p1), short(n)), f)
85 85 if p2 not in seen and p2 != nullid:
86 86 err(lr, _("unknown parent 2 %s of %s") %
87 87 (short(p2), short(p1)), f)
88 88 except Exception, inst:
89 89 exc(lr, _("checking parents of %s") % short(node), inst, f)
90 90
91 91 if node in seen:
92 92 err(lr, _("duplicate revision %d (%d)") % (i, seen[n]), f)
93 93 seen[n] = i
94 94 return lr
95 95
96 96 revlogv1 = cl.version != revlog.REVLOGV0
97 97 if ui.verbose or not revlogv1:
98 98 ui.status(_("repository uses revlog format %d\n") %
99 99 (revlogv1 and 1 or 0))
100 100
101 101 havecl = len(cl) > 0
102 102 havemf = len(mf) > 0
103 103
104 104 ui.status(_("checking changesets\n"))
105 105 seen = {}
106 106 checklog(cl, "changelog")
107 107 for i in repo:
108 108 n = cl.node(i)
109 109 checkentry(cl, i, n, seen, [i], "changelog")
110 110
111 111 try:
112 112 changes = cl.read(n)
113 113 mflinkrevs.setdefault(changes[0], []).append(i)
114 114 for f in changes[3]:
115 115 filelinkrevs.setdefault(f, []).append(i)
116 116 except Exception, inst:
117 117 exc(i, _("unpacking changeset %s") % short(n), inst)
118 118
119 119 ui.status(_("checking manifests\n"))
120 120 seen = {}
121 121 checklog(mf, "manifest")
122 122 for i in mf:
123 123 n = mf.node(i)
124 124 lr = checkentry(mf, i, n, seen, mflinkrevs.get(n, []), "manifest")
125 125 if n in mflinkrevs:
126 126 del mflinkrevs[n]
127 127
128 128 try:
129 129 for f, fn in mf.readdelta(n).iteritems():
130 130 if not f:
131 131 err(lr, _("file without name in manifest"))
132 132 elif f != "/dev/null":
133 133 fns = filenodes.setdefault(f, {})
134 134 if fn not in fns:
135 135 fns[fn] = n
136 136 except Exception, inst:
137 137 exc(lr, _("reading manifest delta %s") % short(n), inst)
138 138
139 139 ui.status(_("crosschecking files in changesets and manifests\n"))
140 140
141 141 if havemf:
142 142 for c, m in util.sort([(c, m) for m in mflinkrevs for c in mflinkrevs[m]]):
143 143 err(c, _("changeset refers to unknown manifest %s") % short(m))
144 144 del mflinkrevs
145 145
146 146 for f in util.sort(filelinkrevs):
147 147 if f not in filenodes:
148 148 lr = filelinkrevs[f][0]
149 149 err(lr, _("in changeset but not in manifest"), f)
150 150
151 151 if havecl:
152 152 for f in util.sort(filenodes):
153 153 if f not in filelinkrevs:
154 154 try:
155 155 lr = min([repo.file(f).linkrev(n) for n in filenodes[f]])
156 156 except:
157 157 lr = None
158 158 err(lr, _("in manifest but not in changeset"), f)
159 159
160 160 ui.status(_("checking files\n"))
161 161
162 162 storefiles = {}
163 163 for f, f2, size in repo.store.datafiles():
164 164 if not f:
165 165 err(None, _("cannot decode filename '%s'") % f2)
166 166 elif size > 0:
167 167 storefiles[f] = True
168 168
169 169 files = util.sort(util.unique(filenodes.keys() + filelinkrevs.keys()))
170 170 for f in files:
171 171 fl = repo.file(f)
172 172
173 173 for ff in fl.files():
174 174 try:
175 175 del storefiles[ff]
176 176 except KeyError:
177 177 err(0, _("missing revlog!"), ff)
178 178
179 179 checklog(fl, f)
180 180 seen = {}
181 181 for i in fl:
182 182 revisions += 1
183 183 n = fl.node(i)
184 184 lr = checkentry(fl, i, n, seen, filelinkrevs.get(f, []), f)
185 185 if f in filenodes:
186 186 if havemf and n not in filenodes[f]:
187 187 err(lr, _("%s not in manifests") % (short(n)), f)
188 188 else:
189 189 del filenodes[f][n]
190 190
191 191 # verify contents
192 192 try:
193 193 t = fl.read(n)
194 194 rp = fl.renamed(n)
195 195 if len(t) != fl.size(i):
196 196 if not fl._readmeta(n): # ancient copy?
197 197 err(lr, _("unpacked size is %s, %s expected") %
198 198 (len(t), fl.size(i)), f)
199 199 except Exception, inst:
200 200 exc(lr, _("unpacking %s") % short(n), inst, f)
201 201
202 202 # check renames
203 203 try:
204 204 if rp:
205 205 fl2 = repo.file(rp[0])
206 206 if not len(fl2):
207 207 err(lr, _("empty or missing copy source revlog %s:%s")
208 208 % (rp[0], short(rp[1])), f)
209 209 elif rp[1] == nullid:
210 warn(lr, _("copy source revision is nullid %s:%s")
211 % (rp[0], short(rp[1])), f)
210 warn(_("warning: %s@%s: copy source revision is nullid %s:%s")
211 % (f, lr, rp[0], short(rp[1])))
212 212 else:
213 213 rev = fl2.rev(rp[1])
214 214 except Exception, inst:
215 215 exc(lr, _("checking rename of %s") % short(n), inst, f)
216 216
217 217 # cross-check
218 218 if f in filenodes:
219 219 fns = [(mf.linkrev(l), n) for n,l in filenodes[f].items()]
220 220 for lr, node in util.sort(fns):
221 221 err(lr, _("%s in manifests not found") % short(node), f)
222 222
223 223 for f in storefiles:
224 224 warn(_("warning: orphan revlog '%s'") % f)
225 225
226 226 ui.status(_("%d files, %d changesets, %d total revisions\n") %
227 227 (len(files), len(cl), revisions))
228 228 if warnings[0]:
229 229 ui.warn(_("%d warnings encountered!\n") % warnings[0])
230 230 if errors[0]:
231 231 ui.warn(_("%d integrity errors encountered!\n") % errors[0])
232 232 if badrevs:
233 233 ui.warn(_("(first damaged changeset appears to be %d)\n")
234 234 % min(badrevs))
235 235 return 1
General Comments 0
You need to be logged in to leave comments. Login now