##// END OF EJS Templates
verify: fix exception formatting bug in Python 3...
Augie Fackler -
r36595:d85ef895 default
parent child Browse files
Show More
@@ -1,486 +1,487 b''
1 # verify.py - repository integrity checking for Mercurial
1 # verify.py - repository integrity checking for Mercurial
2 #
2 #
3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import os
10 import os
11
11
12 from .i18n import _
12 from .i18n import _
13 from .node import (
13 from .node import (
14 nullid,
14 nullid,
15 short,
15 short,
16 )
16 )
17
17
18 from . import (
18 from . import (
19 error,
19 error,
20 pycompat,
20 pycompat,
21 revlog,
21 revlog,
22 scmutil,
22 scmutil,
23 util,
23 util,
24 )
24 )
25
25
26 def verify(repo):
26 def verify(repo):
27 with repo.lock():
27 with repo.lock():
28 return verifier(repo).verify()
28 return verifier(repo).verify()
29
29
30 def _normpath(f):
30 def _normpath(f):
31 # under hg < 2.4, convert didn't sanitize paths properly, so a
31 # under hg < 2.4, convert didn't sanitize paths properly, so a
32 # converted repo may contain repeated slashes
32 # converted repo may contain repeated slashes
33 while '//' in f:
33 while '//' in f:
34 f = f.replace('//', '/')
34 f = f.replace('//', '/')
35 return f
35 return f
36
36
37 class verifier(object):
37 class verifier(object):
38 # The match argument is always None in hg core, but e.g. the narrowhg
38 # The match argument is always None in hg core, but e.g. the narrowhg
39 # extension will pass in a matcher here.
39 # extension will pass in a matcher here.
40 def __init__(self, repo, match=None):
40 def __init__(self, repo, match=None):
41 self.repo = repo.unfiltered()
41 self.repo = repo.unfiltered()
42 self.ui = repo.ui
42 self.ui = repo.ui
43 self.match = match or scmutil.matchall(repo)
43 self.match = match or scmutil.matchall(repo)
44 self.badrevs = set()
44 self.badrevs = set()
45 self.errors = 0
45 self.errors = 0
46 self.warnings = 0
46 self.warnings = 0
47 self.havecl = len(repo.changelog) > 0
47 self.havecl = len(repo.changelog) > 0
48 self.havemf = len(repo.manifestlog._revlog) > 0
48 self.havemf = len(repo.manifestlog._revlog) > 0
49 self.revlogv1 = repo.changelog.version != revlog.REVLOGV0
49 self.revlogv1 = repo.changelog.version != revlog.REVLOGV0
50 self.lrugetctx = util.lrucachefunc(repo.changectx)
50 self.lrugetctx = util.lrucachefunc(repo.changectx)
51 self.refersmf = False
51 self.refersmf = False
52 self.fncachewarned = False
52 self.fncachewarned = False
53 # developer config: verify.skipflags
53 # developer config: verify.skipflags
54 self.skipflags = repo.ui.configint('verify', 'skipflags')
54 self.skipflags = repo.ui.configint('verify', 'skipflags')
55
55
56 def warn(self, msg):
56 def warn(self, msg):
57 self.ui.warn(msg + "\n")
57 self.ui.warn(msg + "\n")
58 self.warnings += 1
58 self.warnings += 1
59
59
60 def err(self, linkrev, msg, filename=None):
60 def err(self, linkrev, msg, filename=None):
61 if linkrev is not None:
61 if linkrev is not None:
62 self.badrevs.add(linkrev)
62 self.badrevs.add(linkrev)
63 linkrev = "%d" % linkrev
63 linkrev = "%d" % linkrev
64 else:
64 else:
65 linkrev = '?'
65 linkrev = '?'
66 msg = "%s: %s" % (linkrev, msg)
66 msg = "%s: %s" % (linkrev, msg)
67 if filename:
67 if filename:
68 msg = "%s@%s" % (filename, msg)
68 msg = "%s@%s" % (filename, msg)
69 self.ui.warn(" " + msg + "\n")
69 self.ui.warn(" " + msg + "\n")
70 self.errors += 1
70 self.errors += 1
71
71
72 def exc(self, linkrev, msg, inst, filename=None):
72 def exc(self, linkrev, msg, inst, filename=None):
73 if not str(inst):
73 fmsg = pycompat.bytestr(inst)
74 inst = repr(inst)
74 if not fmsg:
75 self.err(linkrev, "%s: %s" % (msg, inst), filename)
75 fmsg = pycompat.byterepr(inst)
76 self.err(linkrev, "%s: %s" % (msg, fmsg), filename)
76
77
77 def checklog(self, obj, name, linkrev):
78 def checklog(self, obj, name, linkrev):
78 if not len(obj) and (self.havecl or self.havemf):
79 if not len(obj) and (self.havecl or self.havemf):
79 self.err(linkrev, _("empty or missing %s") % name)
80 self.err(linkrev, _("empty or missing %s") % name)
80 return
81 return
81
82
82 d = obj.checksize()
83 d = obj.checksize()
83 if d[0]:
84 if d[0]:
84 self.err(None, _("data length off by %d bytes") % d[0], name)
85 self.err(None, _("data length off by %d bytes") % d[0], name)
85 if d[1]:
86 if d[1]:
86 self.err(None, _("index contains %d extra bytes") % d[1], name)
87 self.err(None, _("index contains %d extra bytes") % d[1], name)
87
88
88 if obj.version != revlog.REVLOGV0:
89 if obj.version != revlog.REVLOGV0:
89 if not self.revlogv1:
90 if not self.revlogv1:
90 self.warn(_("warning: `%s' uses revlog format 1") % name)
91 self.warn(_("warning: `%s' uses revlog format 1") % name)
91 elif self.revlogv1:
92 elif self.revlogv1:
92 self.warn(_("warning: `%s' uses revlog format 0") % name)
93 self.warn(_("warning: `%s' uses revlog format 0") % name)
93
94
94 def checkentry(self, obj, i, node, seen, linkrevs, f):
95 def checkentry(self, obj, i, node, seen, linkrevs, f):
95 lr = obj.linkrev(obj.rev(node))
96 lr = obj.linkrev(obj.rev(node))
96 if lr < 0 or (self.havecl and lr not in linkrevs):
97 if lr < 0 or (self.havecl and lr not in linkrevs):
97 if lr < 0 or lr >= len(self.repo.changelog):
98 if lr < 0 or lr >= len(self.repo.changelog):
98 msg = _("rev %d points to nonexistent changeset %d")
99 msg = _("rev %d points to nonexistent changeset %d")
99 else:
100 else:
100 msg = _("rev %d points to unexpected changeset %d")
101 msg = _("rev %d points to unexpected changeset %d")
101 self.err(None, msg % (i, lr), f)
102 self.err(None, msg % (i, lr), f)
102 if linkrevs:
103 if linkrevs:
103 if f and len(linkrevs) > 1:
104 if f and len(linkrevs) > 1:
104 try:
105 try:
105 # attempt to filter down to real linkrevs
106 # attempt to filter down to real linkrevs
106 linkrevs = [l for l in linkrevs
107 linkrevs = [l for l in linkrevs
107 if self.lrugetctx(l)[f].filenode() == node]
108 if self.lrugetctx(l)[f].filenode() == node]
108 except Exception:
109 except Exception:
109 pass
110 pass
110 self.warn(_(" (expected %s)") % " ".join
111 self.warn(_(" (expected %s)") % " ".join
111 (map(pycompat.bytestr, linkrevs)))
112 (map(pycompat.bytestr, linkrevs)))
112 lr = None # can't be trusted
113 lr = None # can't be trusted
113
114
114 try:
115 try:
115 p1, p2 = obj.parents(node)
116 p1, p2 = obj.parents(node)
116 if p1 not in seen and p1 != nullid:
117 if p1 not in seen and p1 != nullid:
117 self.err(lr, _("unknown parent 1 %s of %s") %
118 self.err(lr, _("unknown parent 1 %s of %s") %
118 (short(p1), short(node)), f)
119 (short(p1), short(node)), f)
119 if p2 not in seen and p2 != nullid:
120 if p2 not in seen and p2 != nullid:
120 self.err(lr, _("unknown parent 2 %s of %s") %
121 self.err(lr, _("unknown parent 2 %s of %s") %
121 (short(p2), short(node)), f)
122 (short(p2), short(node)), f)
122 except Exception as inst:
123 except Exception as inst:
123 self.exc(lr, _("checking parents of %s") % short(node), inst, f)
124 self.exc(lr, _("checking parents of %s") % short(node), inst, f)
124
125
125 if node in seen:
126 if node in seen:
126 self.err(lr, _("duplicate revision %d (%d)") % (i, seen[node]), f)
127 self.err(lr, _("duplicate revision %d (%d)") % (i, seen[node]), f)
127 seen[node] = i
128 seen[node] = i
128 return lr
129 return lr
129
130
130 def verify(self):
131 def verify(self):
131 repo = self.repo
132 repo = self.repo
132
133
133 ui = repo.ui
134 ui = repo.ui
134
135
135 if not repo.url().startswith('file:'):
136 if not repo.url().startswith('file:'):
136 raise error.Abort(_("cannot verify bundle or remote repos"))
137 raise error.Abort(_("cannot verify bundle or remote repos"))
137
138
138 if os.path.exists(repo.sjoin("journal")):
139 if os.path.exists(repo.sjoin("journal")):
139 ui.warn(_("abandoned transaction found - run hg recover\n"))
140 ui.warn(_("abandoned transaction found - run hg recover\n"))
140
141
141 if ui.verbose or not self.revlogv1:
142 if ui.verbose or not self.revlogv1:
142 ui.status(_("repository uses revlog format %d\n") %
143 ui.status(_("repository uses revlog format %d\n") %
143 (self.revlogv1 and 1 or 0))
144 (self.revlogv1 and 1 or 0))
144
145
145 mflinkrevs, filelinkrevs = self._verifychangelog()
146 mflinkrevs, filelinkrevs = self._verifychangelog()
146
147
147 filenodes = self._verifymanifest(mflinkrevs)
148 filenodes = self._verifymanifest(mflinkrevs)
148 del mflinkrevs
149 del mflinkrevs
149
150
150 self._crosscheckfiles(filelinkrevs, filenodes)
151 self._crosscheckfiles(filelinkrevs, filenodes)
151
152
152 totalfiles, filerevisions = self._verifyfiles(filenodes, filelinkrevs)
153 totalfiles, filerevisions = self._verifyfiles(filenodes, filelinkrevs)
153
154
154 ui.status(_("%d files, %d changesets, %d total revisions\n") %
155 ui.status(_("%d files, %d changesets, %d total revisions\n") %
155 (totalfiles, len(repo.changelog), filerevisions))
156 (totalfiles, len(repo.changelog), filerevisions))
156 if self.warnings:
157 if self.warnings:
157 ui.warn(_("%d warnings encountered!\n") % self.warnings)
158 ui.warn(_("%d warnings encountered!\n") % self.warnings)
158 if self.fncachewarned:
159 if self.fncachewarned:
159 ui.warn(_('hint: run "hg debugrebuildfncache" to recover from '
160 ui.warn(_('hint: run "hg debugrebuildfncache" to recover from '
160 'corrupt fncache\n'))
161 'corrupt fncache\n'))
161 if self.errors:
162 if self.errors:
162 ui.warn(_("%d integrity errors encountered!\n") % self.errors)
163 ui.warn(_("%d integrity errors encountered!\n") % self.errors)
163 if self.badrevs:
164 if self.badrevs:
164 ui.warn(_("(first damaged changeset appears to be %d)\n")
165 ui.warn(_("(first damaged changeset appears to be %d)\n")
165 % min(self.badrevs))
166 % min(self.badrevs))
166 return 1
167 return 1
167
168
168 def _verifychangelog(self):
169 def _verifychangelog(self):
169 ui = self.ui
170 ui = self.ui
170 repo = self.repo
171 repo = self.repo
171 match = self.match
172 match = self.match
172 cl = repo.changelog
173 cl = repo.changelog
173
174
174 ui.status(_("checking changesets\n"))
175 ui.status(_("checking changesets\n"))
175 mflinkrevs = {}
176 mflinkrevs = {}
176 filelinkrevs = {}
177 filelinkrevs = {}
177 seen = {}
178 seen = {}
178 self.checklog(cl, "changelog", 0)
179 self.checklog(cl, "changelog", 0)
179 total = len(repo)
180 total = len(repo)
180 for i in repo:
181 for i in repo:
181 ui.progress(_('checking'), i, total=total, unit=_('changesets'))
182 ui.progress(_('checking'), i, total=total, unit=_('changesets'))
182 n = cl.node(i)
183 n = cl.node(i)
183 self.checkentry(cl, i, n, seen, [i], "changelog")
184 self.checkentry(cl, i, n, seen, [i], "changelog")
184
185
185 try:
186 try:
186 changes = cl.read(n)
187 changes = cl.read(n)
187 if changes[0] != nullid:
188 if changes[0] != nullid:
188 mflinkrevs.setdefault(changes[0], []).append(i)
189 mflinkrevs.setdefault(changes[0], []).append(i)
189 self.refersmf = True
190 self.refersmf = True
190 for f in changes[3]:
191 for f in changes[3]:
191 if match(f):
192 if match(f):
192 filelinkrevs.setdefault(_normpath(f), []).append(i)
193 filelinkrevs.setdefault(_normpath(f), []).append(i)
193 except Exception as inst:
194 except Exception as inst:
194 self.refersmf = True
195 self.refersmf = True
195 self.exc(i, _("unpacking changeset %s") % short(n), inst)
196 self.exc(i, _("unpacking changeset %s") % short(n), inst)
196 ui.progress(_('checking'), None)
197 ui.progress(_('checking'), None)
197 return mflinkrevs, filelinkrevs
198 return mflinkrevs, filelinkrevs
198
199
199 def _verifymanifest(self, mflinkrevs, dir="", storefiles=None,
200 def _verifymanifest(self, mflinkrevs, dir="", storefiles=None,
200 progress=None):
201 progress=None):
201 repo = self.repo
202 repo = self.repo
202 ui = self.ui
203 ui = self.ui
203 match = self.match
204 match = self.match
204 mfl = self.repo.manifestlog
205 mfl = self.repo.manifestlog
205 mf = mfl._revlog.dirlog(dir)
206 mf = mfl._revlog.dirlog(dir)
206
207
207 if not dir:
208 if not dir:
208 self.ui.status(_("checking manifests\n"))
209 self.ui.status(_("checking manifests\n"))
209
210
210 filenodes = {}
211 filenodes = {}
211 subdirnodes = {}
212 subdirnodes = {}
212 seen = {}
213 seen = {}
213 label = "manifest"
214 label = "manifest"
214 if dir:
215 if dir:
215 label = dir
216 label = dir
216 revlogfiles = mf.files()
217 revlogfiles = mf.files()
217 storefiles.difference_update(revlogfiles)
218 storefiles.difference_update(revlogfiles)
218 if progress: # should be true since we're in a subdirectory
219 if progress: # should be true since we're in a subdirectory
219 progress()
220 progress()
220 if self.refersmf:
221 if self.refersmf:
221 # Do not check manifest if there are only changelog entries with
222 # Do not check manifest if there are only changelog entries with
222 # null manifests.
223 # null manifests.
223 self.checklog(mf, label, 0)
224 self.checklog(mf, label, 0)
224 total = len(mf)
225 total = len(mf)
225 for i in mf:
226 for i in mf:
226 if not dir:
227 if not dir:
227 ui.progress(_('checking'), i, total=total, unit=_('manifests'))
228 ui.progress(_('checking'), i, total=total, unit=_('manifests'))
228 n = mf.node(i)
229 n = mf.node(i)
229 lr = self.checkentry(mf, i, n, seen, mflinkrevs.get(n, []), label)
230 lr = self.checkentry(mf, i, n, seen, mflinkrevs.get(n, []), label)
230 if n in mflinkrevs:
231 if n in mflinkrevs:
231 del mflinkrevs[n]
232 del mflinkrevs[n]
232 elif dir:
233 elif dir:
233 self.err(lr, _("%s not in parent-directory manifest") %
234 self.err(lr, _("%s not in parent-directory manifest") %
234 short(n), label)
235 short(n), label)
235 else:
236 else:
236 self.err(lr, _("%s not in changesets") % short(n), label)
237 self.err(lr, _("%s not in changesets") % short(n), label)
237
238
238 try:
239 try:
239 mfdelta = mfl.get(dir, n).readdelta(shallow=True)
240 mfdelta = mfl.get(dir, n).readdelta(shallow=True)
240 for f, fn, fl in mfdelta.iterentries():
241 for f, fn, fl in mfdelta.iterentries():
241 if not f:
242 if not f:
242 self.err(lr, _("entry without name in manifest"))
243 self.err(lr, _("entry without name in manifest"))
243 elif f == "/dev/null": # ignore this in very old repos
244 elif f == "/dev/null": # ignore this in very old repos
244 continue
245 continue
245 fullpath = dir + _normpath(f)
246 fullpath = dir + _normpath(f)
246 if fl == 't':
247 if fl == 't':
247 if not match.visitdir(fullpath):
248 if not match.visitdir(fullpath):
248 continue
249 continue
249 subdirnodes.setdefault(fullpath + '/', {}).setdefault(
250 subdirnodes.setdefault(fullpath + '/', {}).setdefault(
250 fn, []).append(lr)
251 fn, []).append(lr)
251 else:
252 else:
252 if not match(fullpath):
253 if not match(fullpath):
253 continue
254 continue
254 filenodes.setdefault(fullpath, {}).setdefault(fn, lr)
255 filenodes.setdefault(fullpath, {}).setdefault(fn, lr)
255 except Exception as inst:
256 except Exception as inst:
256 self.exc(lr, _("reading delta %s") % short(n), inst, label)
257 self.exc(lr, _("reading delta %s") % short(n), inst, label)
257 if not dir:
258 if not dir:
258 ui.progress(_('checking'), None)
259 ui.progress(_('checking'), None)
259
260
260 if self.havemf:
261 if self.havemf:
261 for c, m in sorted([(c, m) for m in mflinkrevs
262 for c, m in sorted([(c, m) for m in mflinkrevs
262 for c in mflinkrevs[m]]):
263 for c in mflinkrevs[m]]):
263 if dir:
264 if dir:
264 self.err(c, _("parent-directory manifest refers to unknown "
265 self.err(c, _("parent-directory manifest refers to unknown "
265 "revision %s") % short(m), label)
266 "revision %s") % short(m), label)
266 else:
267 else:
267 self.err(c, _("changeset refers to unknown revision %s") %
268 self.err(c, _("changeset refers to unknown revision %s") %
268 short(m), label)
269 short(m), label)
269
270
270 if not dir and subdirnodes:
271 if not dir and subdirnodes:
271 self.ui.status(_("checking directory manifests\n"))
272 self.ui.status(_("checking directory manifests\n"))
272 storefiles = set()
273 storefiles = set()
273 subdirs = set()
274 subdirs = set()
274 revlogv1 = self.revlogv1
275 revlogv1 = self.revlogv1
275 for f, f2, size in repo.store.datafiles():
276 for f, f2, size in repo.store.datafiles():
276 if not f:
277 if not f:
277 self.err(None, _("cannot decode filename '%s'") % f2)
278 self.err(None, _("cannot decode filename '%s'") % f2)
278 elif (size > 0 or not revlogv1) and f.startswith('meta/'):
279 elif (size > 0 or not revlogv1) and f.startswith('meta/'):
279 storefiles.add(_normpath(f))
280 storefiles.add(_normpath(f))
280 subdirs.add(os.path.dirname(f))
281 subdirs.add(os.path.dirname(f))
281 subdircount = len(subdirs)
282 subdircount = len(subdirs)
282 currentsubdir = [0]
283 currentsubdir = [0]
283 def progress():
284 def progress():
284 currentsubdir[0] += 1
285 currentsubdir[0] += 1
285 ui.progress(_('checking'), currentsubdir[0], total=subdircount,
286 ui.progress(_('checking'), currentsubdir[0], total=subdircount,
286 unit=_('manifests'))
287 unit=_('manifests'))
287
288
288 for subdir, linkrevs in subdirnodes.iteritems():
289 for subdir, linkrevs in subdirnodes.iteritems():
289 subdirfilenodes = self._verifymanifest(linkrevs, subdir, storefiles,
290 subdirfilenodes = self._verifymanifest(linkrevs, subdir, storefiles,
290 progress)
291 progress)
291 for f, onefilenodes in subdirfilenodes.iteritems():
292 for f, onefilenodes in subdirfilenodes.iteritems():
292 filenodes.setdefault(f, {}).update(onefilenodes)
293 filenodes.setdefault(f, {}).update(onefilenodes)
293
294
294 if not dir and subdirnodes:
295 if not dir and subdirnodes:
295 ui.progress(_('checking'), None)
296 ui.progress(_('checking'), None)
296 for f in sorted(storefiles):
297 for f in sorted(storefiles):
297 self.warn(_("warning: orphan revlog '%s'") % f)
298 self.warn(_("warning: orphan revlog '%s'") % f)
298
299
299 return filenodes
300 return filenodes
300
301
301 def _crosscheckfiles(self, filelinkrevs, filenodes):
302 def _crosscheckfiles(self, filelinkrevs, filenodes):
302 repo = self.repo
303 repo = self.repo
303 ui = self.ui
304 ui = self.ui
304 ui.status(_("crosschecking files in changesets and manifests\n"))
305 ui.status(_("crosschecking files in changesets and manifests\n"))
305
306
306 total = len(filelinkrevs) + len(filenodes)
307 total = len(filelinkrevs) + len(filenodes)
307 count = 0
308 count = 0
308 if self.havemf:
309 if self.havemf:
309 for f in sorted(filelinkrevs):
310 for f in sorted(filelinkrevs):
310 count += 1
311 count += 1
311 ui.progress(_('crosschecking'), count, total=total)
312 ui.progress(_('crosschecking'), count, total=total)
312 if f not in filenodes:
313 if f not in filenodes:
313 lr = filelinkrevs[f][0]
314 lr = filelinkrevs[f][0]
314 self.err(lr, _("in changeset but not in manifest"), f)
315 self.err(lr, _("in changeset but not in manifest"), f)
315
316
316 if self.havecl:
317 if self.havecl:
317 for f in sorted(filenodes):
318 for f in sorted(filenodes):
318 count += 1
319 count += 1
319 ui.progress(_('crosschecking'), count, total=total)
320 ui.progress(_('crosschecking'), count, total=total)
320 if f not in filelinkrevs:
321 if f not in filelinkrevs:
321 try:
322 try:
322 fl = repo.file(f)
323 fl = repo.file(f)
323 lr = min([fl.linkrev(fl.rev(n)) for n in filenodes[f]])
324 lr = min([fl.linkrev(fl.rev(n)) for n in filenodes[f]])
324 except Exception:
325 except Exception:
325 lr = None
326 lr = None
326 self.err(lr, _("in manifest but not in changeset"), f)
327 self.err(lr, _("in manifest but not in changeset"), f)
327
328
328 ui.progress(_('crosschecking'), None)
329 ui.progress(_('crosschecking'), None)
329
330
330 def _verifyfiles(self, filenodes, filelinkrevs):
331 def _verifyfiles(self, filenodes, filelinkrevs):
331 repo = self.repo
332 repo = self.repo
332 ui = self.ui
333 ui = self.ui
333 lrugetctx = self.lrugetctx
334 lrugetctx = self.lrugetctx
334 revlogv1 = self.revlogv1
335 revlogv1 = self.revlogv1
335 havemf = self.havemf
336 havemf = self.havemf
336 ui.status(_("checking files\n"))
337 ui.status(_("checking files\n"))
337
338
338 storefiles = set()
339 storefiles = set()
339 for f, f2, size in repo.store.datafiles():
340 for f, f2, size in repo.store.datafiles():
340 if not f:
341 if not f:
341 self.err(None, _("cannot decode filename '%s'") % f2)
342 self.err(None, _("cannot decode filename '%s'") % f2)
342 elif (size > 0 or not revlogv1) and f.startswith('data/'):
343 elif (size > 0 or not revlogv1) and f.startswith('data/'):
343 storefiles.add(_normpath(f))
344 storefiles.add(_normpath(f))
344
345
345 files = sorted(set(filenodes) | set(filelinkrevs))
346 files = sorted(set(filenodes) | set(filelinkrevs))
346 total = len(files)
347 total = len(files)
347 revisions = 0
348 revisions = 0
348 for i, f in enumerate(files):
349 for i, f in enumerate(files):
349 ui.progress(_('checking'), i, item=f, total=total, unit=_('files'))
350 ui.progress(_('checking'), i, item=f, total=total, unit=_('files'))
350 try:
351 try:
351 linkrevs = filelinkrevs[f]
352 linkrevs = filelinkrevs[f]
352 except KeyError:
353 except KeyError:
353 # in manifest but not in changelog
354 # in manifest but not in changelog
354 linkrevs = []
355 linkrevs = []
355
356
356 if linkrevs:
357 if linkrevs:
357 lr = linkrevs[0]
358 lr = linkrevs[0]
358 else:
359 else:
359 lr = None
360 lr = None
360
361
361 try:
362 try:
362 fl = repo.file(f)
363 fl = repo.file(f)
363 except error.RevlogError as e:
364 except error.RevlogError as e:
364 self.err(lr, _("broken revlog! (%s)") % e, f)
365 self.err(lr, _("broken revlog! (%s)") % e, f)
365 continue
366 continue
366
367
367 for ff in fl.files():
368 for ff in fl.files():
368 try:
369 try:
369 storefiles.remove(ff)
370 storefiles.remove(ff)
370 except KeyError:
371 except KeyError:
371 self.warn(_(" warning: revlog '%s' not in fncache!") % ff)
372 self.warn(_(" warning: revlog '%s' not in fncache!") % ff)
372 self.fncachewarned = True
373 self.fncachewarned = True
373
374
374 self.checklog(fl, f, lr)
375 self.checklog(fl, f, lr)
375 seen = {}
376 seen = {}
376 rp = None
377 rp = None
377 for i in fl:
378 for i in fl:
378 revisions += 1
379 revisions += 1
379 n = fl.node(i)
380 n = fl.node(i)
380 lr = self.checkentry(fl, i, n, seen, linkrevs, f)
381 lr = self.checkentry(fl, i, n, seen, linkrevs, f)
381 if f in filenodes:
382 if f in filenodes:
382 if havemf and n not in filenodes[f]:
383 if havemf and n not in filenodes[f]:
383 self.err(lr, _("%s not in manifests") % (short(n)), f)
384 self.err(lr, _("%s not in manifests") % (short(n)), f)
384 else:
385 else:
385 del filenodes[f][n]
386 del filenodes[f][n]
386
387
387 # Verify contents. 4 cases to care about:
388 # Verify contents. 4 cases to care about:
388 #
389 #
389 # common: the most common case
390 # common: the most common case
390 # rename: with a rename
391 # rename: with a rename
391 # meta: file content starts with b'\1\n', the metadata
392 # meta: file content starts with b'\1\n', the metadata
392 # header defined in filelog.py, but without a rename
393 # header defined in filelog.py, but without a rename
393 # ext: content stored externally
394 # ext: content stored externally
394 #
395 #
395 # More formally, their differences are shown below:
396 # More formally, their differences are shown below:
396 #
397 #
397 # | common | rename | meta | ext
398 # | common | rename | meta | ext
398 # -------------------------------------------------------
399 # -------------------------------------------------------
399 # flags() | 0 | 0 | 0 | not 0
400 # flags() | 0 | 0 | 0 | not 0
400 # renamed() | False | True | False | ?
401 # renamed() | False | True | False | ?
401 # rawtext[0:2]=='\1\n'| False | True | True | ?
402 # rawtext[0:2]=='\1\n'| False | True | True | ?
402 #
403 #
403 # "rawtext" means the raw text stored in revlog data, which
404 # "rawtext" means the raw text stored in revlog data, which
404 # could be retrieved by "revision(rev, raw=True)". "text"
405 # could be retrieved by "revision(rev, raw=True)". "text"
405 # mentioned below is "revision(rev, raw=False)".
406 # mentioned below is "revision(rev, raw=False)".
406 #
407 #
407 # There are 3 different lengths stored physically:
408 # There are 3 different lengths stored physically:
408 # 1. L1: rawsize, stored in revlog index
409 # 1. L1: rawsize, stored in revlog index
409 # 2. L2: len(rawtext), stored in revlog data
410 # 2. L2: len(rawtext), stored in revlog data
410 # 3. L3: len(text), stored in revlog data if flags==0, or
411 # 3. L3: len(text), stored in revlog data if flags==0, or
411 # possibly somewhere else if flags!=0
412 # possibly somewhere else if flags!=0
412 #
413 #
413 # L1 should be equal to L2. L3 could be different from them.
414 # L1 should be equal to L2. L3 could be different from them.
414 # "text" may or may not affect commit hash depending on flag
415 # "text" may or may not affect commit hash depending on flag
415 # processors (see revlog.addflagprocessor).
416 # processors (see revlog.addflagprocessor).
416 #
417 #
417 # | common | rename | meta | ext
418 # | common | rename | meta | ext
418 # -------------------------------------------------
419 # -------------------------------------------------
419 # rawsize() | L1 | L1 | L1 | L1
420 # rawsize() | L1 | L1 | L1 | L1
420 # size() | L1 | L2-LM | L1(*) | L1 (?)
421 # size() | L1 | L2-LM | L1(*) | L1 (?)
421 # len(rawtext) | L2 | L2 | L2 | L2
422 # len(rawtext) | L2 | L2 | L2 | L2
422 # len(text) | L2 | L2 | L2 | L3
423 # len(text) | L2 | L2 | L2 | L3
423 # len(read()) | L2 | L2-LM | L2-LM | L3 (?)
424 # len(read()) | L2 | L2-LM | L2-LM | L3 (?)
424 #
425 #
425 # LM: length of metadata, depending on rawtext
426 # LM: length of metadata, depending on rawtext
426 # (*): not ideal, see comment in filelog.size
427 # (*): not ideal, see comment in filelog.size
427 # (?): could be "- len(meta)" if the resolved content has
428 # (?): could be "- len(meta)" if the resolved content has
428 # rename metadata
429 # rename metadata
429 #
430 #
430 # Checks needed to be done:
431 # Checks needed to be done:
431 # 1. length check: L1 == L2, in all cases.
432 # 1. length check: L1 == L2, in all cases.
432 # 2. hash check: depending on flag processor, we may need to
433 # 2. hash check: depending on flag processor, we may need to
433 # use either "text" (external), or "rawtext" (in revlog).
434 # use either "text" (external), or "rawtext" (in revlog).
434 try:
435 try:
435 skipflags = self.skipflags
436 skipflags = self.skipflags
436 if skipflags:
437 if skipflags:
437 skipflags &= fl.flags(i)
438 skipflags &= fl.flags(i)
438 if not skipflags:
439 if not skipflags:
439 fl.read(n) # side effect: read content and do checkhash
440 fl.read(n) # side effect: read content and do checkhash
440 rp = fl.renamed(n)
441 rp = fl.renamed(n)
441 # the "L1 == L2" check
442 # the "L1 == L2" check
442 l1 = fl.rawsize(i)
443 l1 = fl.rawsize(i)
443 l2 = len(fl.revision(n, raw=True))
444 l2 = len(fl.revision(n, raw=True))
444 if l1 != l2:
445 if l1 != l2:
445 self.err(lr, _("unpacked size is %s, %s expected") %
446 self.err(lr, _("unpacked size is %s, %s expected") %
446 (l2, l1), f)
447 (l2, l1), f)
447 except error.CensoredNodeError:
448 except error.CensoredNodeError:
448 # experimental config: censor.policy
449 # experimental config: censor.policy
449 if ui.config("censor", "policy") == "abort":
450 if ui.config("censor", "policy") == "abort":
450 self.err(lr, _("censored file data"), f)
451 self.err(lr, _("censored file data"), f)
451 except Exception as inst:
452 except Exception as inst:
452 self.exc(lr, _("unpacking %s") % short(n), inst, f)
453 self.exc(lr, _("unpacking %s") % short(n), inst, f)
453
454
454 # check renames
455 # check renames
455 try:
456 try:
456 if rp:
457 if rp:
457 if lr is not None and ui.verbose:
458 if lr is not None and ui.verbose:
458 ctx = lrugetctx(lr)
459 ctx = lrugetctx(lr)
459 if not any(rp[0] in pctx for pctx in ctx.parents()):
460 if not any(rp[0] in pctx for pctx in ctx.parents()):
460 self.warn(_("warning: copy source of '%s' not"
461 self.warn(_("warning: copy source of '%s' not"
461 " in parents of %s") % (f, ctx))
462 " in parents of %s") % (f, ctx))
462 fl2 = repo.file(rp[0])
463 fl2 = repo.file(rp[0])
463 if not len(fl2):
464 if not len(fl2):
464 self.err(lr, _("empty or missing copy source "
465 self.err(lr, _("empty or missing copy source "
465 "revlog %s:%s") % (rp[0], short(rp[1])), f)
466 "revlog %s:%s") % (rp[0], short(rp[1])), f)
466 elif rp[1] == nullid:
467 elif rp[1] == nullid:
467 ui.note(_("warning: %s@%s: copy source"
468 ui.note(_("warning: %s@%s: copy source"
468 " revision is nullid %s:%s\n")
469 " revision is nullid %s:%s\n")
469 % (f, lr, rp[0], short(rp[1])))
470 % (f, lr, rp[0], short(rp[1])))
470 else:
471 else:
471 fl2.rev(rp[1])
472 fl2.rev(rp[1])
472 except Exception as inst:
473 except Exception as inst:
473 self.exc(lr, _("checking rename of %s") % short(n), inst, f)
474 self.exc(lr, _("checking rename of %s") % short(n), inst, f)
474
475
475 # cross-check
476 # cross-check
476 if f in filenodes:
477 if f in filenodes:
477 fns = [(v, k) for k, v in filenodes[f].iteritems()]
478 fns = [(v, k) for k, v in filenodes[f].iteritems()]
478 for lr, node in sorted(fns):
479 for lr, node in sorted(fns):
479 self.err(lr, _("manifest refers to unknown revision %s") %
480 self.err(lr, _("manifest refers to unknown revision %s") %
480 short(node), f)
481 short(node), f)
481 ui.progress(_('checking'), None)
482 ui.progress(_('checking'), None)
482
483
483 for f in sorted(storefiles):
484 for f in sorted(storefiles):
484 self.warn(_("warning: orphan revlog '%s'") % f)
485 self.warn(_("warning: orphan revlog '%s'") % f)
485
486
486 return len(files), revisions
487 return len(files), revisions
General Comments 0
You need to be logged in to leave comments. Login now