Show More
@@ -1,460 +1,461 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 | util, |
|
22 | util, | |
23 | ) |
|
23 | ) | |
24 |
|
24 | |||
25 | def verify(repo): |
|
25 | def verify(repo): | |
26 | with repo.lock(): |
|
26 | with repo.lock(): | |
27 | return verifier(repo).verify() |
|
27 | return verifier(repo).verify() | |
28 |
|
28 | |||
29 | def _normpath(f): |
|
29 | def _normpath(f): | |
30 | # under hg < 2.4, convert didn't sanitize paths properly, so a |
|
30 | # under hg < 2.4, convert didn't sanitize paths properly, so a | |
31 | # converted repo may contain repeated slashes |
|
31 | # converted repo may contain repeated slashes | |
32 | while '//' in f: |
|
32 | while '//' in f: | |
33 | f = f.replace('//', '/') |
|
33 | f = f.replace('//', '/') | |
34 | return f |
|
34 | return f | |
35 |
|
35 | |||
36 | class verifier(object): |
|
36 | class verifier(object): | |
37 | def __init__(self, repo): |
|
37 | def __init__(self, repo): | |
38 | self.repo = repo.unfiltered() |
|
38 | self.repo = repo.unfiltered() | |
39 | self.ui = repo.ui |
|
39 | self.ui = repo.ui | |
40 | self.match = repo.narrowmatch() |
|
40 | self.match = repo.narrowmatch() | |
41 | self.badrevs = set() |
|
41 | self.badrevs = set() | |
42 | self.errors = 0 |
|
42 | self.errors = 0 | |
43 | self.warnings = 0 |
|
43 | self.warnings = 0 | |
44 | self.havecl = len(repo.changelog) > 0 |
|
44 | self.havecl = len(repo.changelog) > 0 | |
45 | self.havemf = len(repo.manifestlog.getstorage(b'')) > 0 |
|
45 | self.havemf = len(repo.manifestlog.getstorage(b'')) > 0 | |
46 | self.revlogv1 = repo.changelog.version != revlog.REVLOGV0 |
|
46 | self.revlogv1 = repo.changelog.version != revlog.REVLOGV0 | |
47 | self.lrugetctx = util.lrucachefunc(repo.__getitem__) |
|
47 | self.lrugetctx = util.lrucachefunc(repo.__getitem__) | |
48 | self.refersmf = False |
|
48 | self.refersmf = False | |
49 | self.fncachewarned = False |
|
49 | self.fncachewarned = False | |
50 | # developer config: verify.skipflags |
|
50 | # developer config: verify.skipflags | |
51 | self.skipflags = repo.ui.configint('verify', 'skipflags') |
|
51 | self.skipflags = repo.ui.configint('verify', 'skipflags') | |
52 | self.warnorphanstorefiles = True |
|
52 | self.warnorphanstorefiles = True | |
53 |
|
53 | |||
54 | def _warn(self, msg): |
|
54 | def _warn(self, msg): | |
55 | """record a "warning" level issue""" |
|
55 | """record a "warning" level issue""" | |
56 | self.ui.warn(msg + "\n") |
|
56 | self.ui.warn(msg + "\n") | |
57 | self.warnings += 1 |
|
57 | self.warnings += 1 | |
58 |
|
58 | |||
59 | def _err(self, linkrev, msg, filename=None): |
|
59 | def _err(self, linkrev, msg, filename=None): | |
60 | """record a "error" level issue""" |
|
60 | """record a "error" level issue""" | |
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 | """record exception raised during the verify process""" |
|
73 | """record exception raised during the verify process""" | |
74 | fmsg = pycompat.bytestr(inst) |
|
74 | fmsg = pycompat.bytestr(inst) | |
75 | if not fmsg: |
|
75 | if not fmsg: | |
76 | fmsg = pycompat.byterepr(inst) |
|
76 | fmsg = pycompat.byterepr(inst) | |
77 | self._err(linkrev, "%s: %s" % (msg, fmsg), filename) |
|
77 | self._err(linkrev, "%s: %s" % (msg, fmsg), filename) | |
78 |
|
78 | |||
79 | def checklog(self, obj, name, linkrev): |
|
79 | def checklog(self, obj, name, linkrev): | |
80 | if not len(obj) and (self.havecl or self.havemf): |
|
80 | if not len(obj) and (self.havecl or self.havemf): | |
81 | self._err(linkrev, _("empty or missing %s") % name) |
|
81 | self._err(linkrev, _("empty or missing %s") % name) | |
82 | return |
|
82 | return | |
83 |
|
83 | |||
84 | d = obj.checksize() |
|
84 | d = obj.checksize() | |
85 | if d[0]: |
|
85 | if d[0]: | |
86 | self.err(None, _("data length off by %d bytes") % d[0], name) |
|
86 | self.err(None, _("data length off by %d bytes") % d[0], name) | |
87 | if d[1]: |
|
87 | if d[1]: | |
88 | self.err(None, _("index contains %d extra bytes") % d[1], name) |
|
88 | self.err(None, _("index contains %d extra bytes") % d[1], name) | |
89 |
|
89 | |||
90 | if obj.version != revlog.REVLOGV0: |
|
90 | if obj.version != revlog.REVLOGV0: | |
91 | if not self.revlogv1: |
|
91 | if not self.revlogv1: | |
92 | self._warn(_("warning: `%s' uses revlog format 1") % name) |
|
92 | self._warn(_("warning: `%s' uses revlog format 1") % name) | |
93 | elif self.revlogv1: |
|
93 | elif self.revlogv1: | |
94 | self._warn(_("warning: `%s' uses revlog format 0") % name) |
|
94 | self._warn(_("warning: `%s' uses revlog format 0") % name) | |
95 |
|
95 | |||
96 | def checkentry(self, obj, i, node, seen, linkrevs, f): |
|
96 | def checkentry(self, obj, i, node, seen, linkrevs, f): | |
97 | lr = obj.linkrev(obj.rev(node)) |
|
97 | lr = obj.linkrev(obj.rev(node)) | |
98 | if lr < 0 or (self.havecl and lr not in linkrevs): |
|
98 | if lr < 0 or (self.havecl and lr not in linkrevs): | |
99 | if lr < 0 or lr >= len(self.repo.changelog): |
|
99 | if lr < 0 or lr >= len(self.repo.changelog): | |
100 | msg = _("rev %d points to nonexistent changeset %d") |
|
100 | msg = _("rev %d points to nonexistent changeset %d") | |
101 | else: |
|
101 | else: | |
102 | msg = _("rev %d points to unexpected changeset %d") |
|
102 | msg = _("rev %d points to unexpected changeset %d") | |
103 | self._err(None, msg % (i, lr), f) |
|
103 | self._err(None, msg % (i, lr), f) | |
104 | if linkrevs: |
|
104 | if linkrevs: | |
105 | if f and len(linkrevs) > 1: |
|
105 | if f and len(linkrevs) > 1: | |
106 | try: |
|
106 | try: | |
107 | # attempt to filter down to real linkrevs |
|
107 | # attempt to filter down to real linkrevs | |
108 | linkrevs = [l for l in linkrevs |
|
108 | linkrevs = [l for l in linkrevs | |
109 | if self.lrugetctx(l)[f].filenode() == node] |
|
109 | if self.lrugetctx(l)[f].filenode() == node] | |
110 | except Exception: |
|
110 | except Exception: | |
111 | pass |
|
111 | pass | |
112 | self._warn(_(" (expected %s)") % " ".join |
|
112 | self._warn(_(" (expected %s)") % " ".join | |
113 | (map(pycompat.bytestr, linkrevs))) |
|
113 | (map(pycompat.bytestr, linkrevs))) | |
114 | lr = None # can't be trusted |
|
114 | lr = None # can't be trusted | |
115 |
|
115 | |||
116 | try: |
|
116 | try: | |
117 | p1, p2 = obj.parents(node) |
|
117 | p1, p2 = obj.parents(node) | |
118 | if p1 not in seen and p1 != nullid: |
|
118 | if p1 not in seen and p1 != nullid: | |
119 | self._err(lr, _("unknown parent 1 %s of %s") % |
|
119 | self._err(lr, _("unknown parent 1 %s of %s") % | |
120 | (short(p1), short(node)), f) |
|
120 | (short(p1), short(node)), f) | |
121 | if p2 not in seen and p2 != nullid: |
|
121 | if p2 not in seen and p2 != nullid: | |
122 | self._err(lr, _("unknown parent 2 %s of %s") % |
|
122 | self._err(lr, _("unknown parent 2 %s of %s") % | |
123 | (short(p2), short(node)), f) |
|
123 | (short(p2), short(node)), f) | |
124 | except Exception as inst: |
|
124 | except Exception as inst: | |
125 | self.exc(lr, _("checking parents of %s") % short(node), inst, f) |
|
125 | self._exc(lr, _("checking parents of %s") % short(node), inst, f) | |
126 |
|
126 | |||
127 | if node in seen: |
|
127 | if node in seen: | |
128 | self._err(lr, _("duplicate revision %d (%d)") % (i, seen[node]), f) |
|
128 | self._err(lr, _("duplicate revision %d (%d)") % (i, seen[node]), f) | |
129 | seen[node] = i |
|
129 | seen[node] = i | |
130 | return lr |
|
130 | return lr | |
131 |
|
131 | |||
132 | def verify(self): |
|
132 | def verify(self): | |
133 | repo = self.repo |
|
133 | repo = self.repo | |
134 |
|
134 | |||
135 | ui = repo.ui |
|
135 | ui = repo.ui | |
136 |
|
136 | |||
137 | if not repo.url().startswith('file:'): |
|
137 | if not repo.url().startswith('file:'): | |
138 | raise error.Abort(_("cannot verify bundle or remote repos")) |
|
138 | raise error.Abort(_("cannot verify bundle or remote repos")) | |
139 |
|
139 | |||
140 | if os.path.exists(repo.sjoin("journal")): |
|
140 | if os.path.exists(repo.sjoin("journal")): | |
141 | ui.warn(_("abandoned transaction found - run hg recover\n")) |
|
141 | ui.warn(_("abandoned transaction found - run hg recover\n")) | |
142 |
|
142 | |||
143 | if ui.verbose or not self.revlogv1: |
|
143 | if ui.verbose or not self.revlogv1: | |
144 | ui.status(_("repository uses revlog format %d\n") % |
|
144 | ui.status(_("repository uses revlog format %d\n") % | |
145 | (self.revlogv1 and 1 or 0)) |
|
145 | (self.revlogv1 and 1 or 0)) | |
146 |
|
146 | |||
147 | mflinkrevs, filelinkrevs = self._verifychangelog() |
|
147 | mflinkrevs, filelinkrevs = self._verifychangelog() | |
148 |
|
148 | |||
149 | filenodes = self._verifymanifest(mflinkrevs) |
|
149 | filenodes = self._verifymanifest(mflinkrevs) | |
150 | del mflinkrevs |
|
150 | del mflinkrevs | |
151 |
|
151 | |||
152 | self._crosscheckfiles(filelinkrevs, filenodes) |
|
152 | self._crosscheckfiles(filelinkrevs, filenodes) | |
153 |
|
153 | |||
154 | totalfiles, filerevisions = self._verifyfiles(filenodes, filelinkrevs) |
|
154 | totalfiles, filerevisions = self._verifyfiles(filenodes, filelinkrevs) | |
155 |
|
155 | |||
156 | ui.status(_("checked %d changesets with %d changes to %d files\n") % |
|
156 | ui.status(_("checked %d changesets with %d changes to %d files\n") % | |
157 | (len(repo.changelog), filerevisions, totalfiles)) |
|
157 | (len(repo.changelog), filerevisions, totalfiles)) | |
158 | if self.warnings: |
|
158 | if self.warnings: | |
159 | ui.warn(_("%d warnings encountered!\n") % self.warnings) |
|
159 | ui.warn(_("%d warnings encountered!\n") % self.warnings) | |
160 | if self.fncachewarned: |
|
160 | if self.fncachewarned: | |
161 | ui.warn(_('hint: run "hg debugrebuildfncache" to recover from ' |
|
161 | ui.warn(_('hint: run "hg debugrebuildfncache" to recover from ' | |
162 | 'corrupt fncache\n')) |
|
162 | 'corrupt fncache\n')) | |
163 | if self.errors: |
|
163 | if self.errors: | |
164 | ui.warn(_("%d integrity errors encountered!\n") % self.errors) |
|
164 | ui.warn(_("%d integrity errors encountered!\n") % self.errors) | |
165 | if self.badrevs: |
|
165 | if self.badrevs: | |
166 | ui.warn(_("(first damaged changeset appears to be %d)\n") |
|
166 | ui.warn(_("(first damaged changeset appears to be %d)\n") | |
167 | % min(self.badrevs)) |
|
167 | % min(self.badrevs)) | |
168 | return 1 |
|
168 | return 1 | |
169 |
|
169 | |||
170 | def _verifychangelog(self): |
|
170 | def _verifychangelog(self): | |
171 | ui = self.ui |
|
171 | ui = self.ui | |
172 | repo = self.repo |
|
172 | repo = self.repo | |
173 | match = self.match |
|
173 | match = self.match | |
174 | cl = repo.changelog |
|
174 | cl = repo.changelog | |
175 |
|
175 | |||
176 | ui.status(_("checking changesets\n")) |
|
176 | ui.status(_("checking changesets\n")) | |
177 | mflinkrevs = {} |
|
177 | mflinkrevs = {} | |
178 | filelinkrevs = {} |
|
178 | filelinkrevs = {} | |
179 | seen = {} |
|
179 | seen = {} | |
180 | self.checklog(cl, "changelog", 0) |
|
180 | self.checklog(cl, "changelog", 0) | |
181 | progress = ui.makeprogress(_('checking'), unit=_('changesets'), |
|
181 | progress = ui.makeprogress(_('checking'), unit=_('changesets'), | |
182 | total=len(repo)) |
|
182 | total=len(repo)) | |
183 | for i in repo: |
|
183 | for i in repo: | |
184 | progress.update(i) |
|
184 | progress.update(i) | |
185 | n = cl.node(i) |
|
185 | n = cl.node(i) | |
186 | self.checkentry(cl, i, n, seen, [i], "changelog") |
|
186 | self.checkentry(cl, i, n, seen, [i], "changelog") | |
187 |
|
187 | |||
188 | try: |
|
188 | try: | |
189 | changes = cl.read(n) |
|
189 | changes = cl.read(n) | |
190 | if changes[0] != nullid: |
|
190 | if changes[0] != nullid: | |
191 | mflinkrevs.setdefault(changes[0], []).append(i) |
|
191 | mflinkrevs.setdefault(changes[0], []).append(i) | |
192 | self.refersmf = True |
|
192 | self.refersmf = True | |
193 | for f in changes[3]: |
|
193 | for f in changes[3]: | |
194 | if match(f): |
|
194 | if match(f): | |
195 | filelinkrevs.setdefault(_normpath(f), []).append(i) |
|
195 | filelinkrevs.setdefault(_normpath(f), []).append(i) | |
196 | except Exception as inst: |
|
196 | except Exception as inst: | |
197 | self.refersmf = True |
|
197 | self.refersmf = True | |
198 | self.exc(i, _("unpacking changeset %s") % short(n), inst) |
|
198 | self._exc(i, _("unpacking changeset %s") % short(n), inst) | |
199 | progress.complete() |
|
199 | progress.complete() | |
200 | return mflinkrevs, filelinkrevs |
|
200 | return mflinkrevs, filelinkrevs | |
201 |
|
201 | |||
202 | def _verifymanifest(self, mflinkrevs, dir="", storefiles=None, |
|
202 | def _verifymanifest(self, mflinkrevs, dir="", storefiles=None, | |
203 | subdirprogress=None): |
|
203 | subdirprogress=None): | |
204 | repo = self.repo |
|
204 | repo = self.repo | |
205 | ui = self.ui |
|
205 | ui = self.ui | |
206 | match = self.match |
|
206 | match = self.match | |
207 | mfl = self.repo.manifestlog |
|
207 | mfl = self.repo.manifestlog | |
208 | mf = mfl.getstorage(dir) |
|
208 | mf = mfl.getstorage(dir) | |
209 |
|
209 | |||
210 | if not dir: |
|
210 | if not dir: | |
211 | self.ui.status(_("checking manifests\n")) |
|
211 | self.ui.status(_("checking manifests\n")) | |
212 |
|
212 | |||
213 | filenodes = {} |
|
213 | filenodes = {} | |
214 | subdirnodes = {} |
|
214 | subdirnodes = {} | |
215 | seen = {} |
|
215 | seen = {} | |
216 | label = "manifest" |
|
216 | label = "manifest" | |
217 | if dir: |
|
217 | if dir: | |
218 | label = dir |
|
218 | label = dir | |
219 | revlogfiles = mf.files() |
|
219 | revlogfiles = mf.files() | |
220 | storefiles.difference_update(revlogfiles) |
|
220 | storefiles.difference_update(revlogfiles) | |
221 | if subdirprogress: # should be true since we're in a subdirectory |
|
221 | if subdirprogress: # should be true since we're in a subdirectory | |
222 | subdirprogress.increment() |
|
222 | subdirprogress.increment() | |
223 | if self.refersmf: |
|
223 | if self.refersmf: | |
224 | # Do not check manifest if there are only changelog entries with |
|
224 | # Do not check manifest if there are only changelog entries with | |
225 | # null manifests. |
|
225 | # null manifests. | |
226 | self.checklog(mf, label, 0) |
|
226 | self.checklog(mf, label, 0) | |
227 | progress = ui.makeprogress(_('checking'), unit=_('manifests'), |
|
227 | progress = ui.makeprogress(_('checking'), unit=_('manifests'), | |
228 | total=len(mf)) |
|
228 | total=len(mf)) | |
229 | for i in mf: |
|
229 | for i in mf: | |
230 | if not dir: |
|
230 | if not dir: | |
231 | progress.update(i) |
|
231 | progress.update(i) | |
232 | n = mf.node(i) |
|
232 | n = mf.node(i) | |
233 | lr = self.checkentry(mf, i, n, seen, mflinkrevs.get(n, []), label) |
|
233 | lr = self.checkentry(mf, i, n, seen, mflinkrevs.get(n, []), label) | |
234 | if n in mflinkrevs: |
|
234 | if n in mflinkrevs: | |
235 | del mflinkrevs[n] |
|
235 | del mflinkrevs[n] | |
236 | elif dir: |
|
236 | elif dir: | |
237 | self._err(lr, _("%s not in parent-directory manifest") % |
|
237 | self._err(lr, _("%s not in parent-directory manifest") % | |
238 | short(n), label) |
|
238 | short(n), label) | |
239 | else: |
|
239 | else: | |
240 | self._err(lr, _("%s not in changesets") % short(n), label) |
|
240 | self._err(lr, _("%s not in changesets") % short(n), label) | |
241 |
|
241 | |||
242 | try: |
|
242 | try: | |
243 | mfdelta = mfl.get(dir, n).readdelta(shallow=True) |
|
243 | mfdelta = mfl.get(dir, n).readdelta(shallow=True) | |
244 | for f, fn, fl in mfdelta.iterentries(): |
|
244 | for f, fn, fl in mfdelta.iterentries(): | |
245 | if not f: |
|
245 | if not f: | |
246 | self._err(lr, _("entry without name in manifest")) |
|
246 | self._err(lr, _("entry without name in manifest")) | |
247 | elif f == "/dev/null": # ignore this in very old repos |
|
247 | elif f == "/dev/null": # ignore this in very old repos | |
248 | continue |
|
248 | continue | |
249 | fullpath = dir + _normpath(f) |
|
249 | fullpath = dir + _normpath(f) | |
250 | if fl == 't': |
|
250 | if fl == 't': | |
251 | if not match.visitdir(fullpath): |
|
251 | if not match.visitdir(fullpath): | |
252 | continue |
|
252 | continue | |
253 | subdirnodes.setdefault(fullpath + '/', {}).setdefault( |
|
253 | subdirnodes.setdefault(fullpath + '/', {}).setdefault( | |
254 | fn, []).append(lr) |
|
254 | fn, []).append(lr) | |
255 | else: |
|
255 | else: | |
256 | if not match(fullpath): |
|
256 | if not match(fullpath): | |
257 | continue |
|
257 | continue | |
258 | filenodes.setdefault(fullpath, {}).setdefault(fn, lr) |
|
258 | filenodes.setdefault(fullpath, {}).setdefault(fn, lr) | |
259 | except Exception as inst: |
|
259 | except Exception as inst: | |
260 | self.exc(lr, _("reading delta %s") % short(n), inst, label) |
|
260 | self._exc(lr, _("reading delta %s") % short(n), inst, label) | |
261 | if not dir: |
|
261 | if not dir: | |
262 | progress.complete() |
|
262 | progress.complete() | |
263 |
|
263 | |||
264 | if self.havemf: |
|
264 | if self.havemf: | |
265 | for c, m in sorted([(c, m) for m in mflinkrevs |
|
265 | for c, m in sorted([(c, m) for m in mflinkrevs | |
266 | for c in mflinkrevs[m]]): |
|
266 | for c in mflinkrevs[m]]): | |
267 | if dir: |
|
267 | if dir: | |
268 | self._err(c, _("parent-directory manifest refers to unknown" |
|
268 | self._err(c, _("parent-directory manifest refers to unknown" | |
269 | " revision %s") % short(m), label) |
|
269 | " revision %s") % short(m), label) | |
270 | else: |
|
270 | else: | |
271 | self._err(c, _("changeset refers to unknown revision %s") % |
|
271 | self._err(c, _("changeset refers to unknown revision %s") % | |
272 | short(m), label) |
|
272 | short(m), label) | |
273 |
|
273 | |||
274 | if not dir and subdirnodes: |
|
274 | if not dir and subdirnodes: | |
275 | self.ui.status(_("checking directory manifests\n")) |
|
275 | self.ui.status(_("checking directory manifests\n")) | |
276 | storefiles = set() |
|
276 | storefiles = set() | |
277 | subdirs = set() |
|
277 | subdirs = set() | |
278 | revlogv1 = self.revlogv1 |
|
278 | revlogv1 = self.revlogv1 | |
279 | for f, f2, size in repo.store.datafiles(): |
|
279 | for f, f2, size in repo.store.datafiles(): | |
280 | if not f: |
|
280 | if not f: | |
281 | self._err(None, _("cannot decode filename '%s'") % f2) |
|
281 | self._err(None, _("cannot decode filename '%s'") % f2) | |
282 | elif (size > 0 or not revlogv1) and f.startswith('meta/'): |
|
282 | elif (size > 0 or not revlogv1) and f.startswith('meta/'): | |
283 | storefiles.add(_normpath(f)) |
|
283 | storefiles.add(_normpath(f)) | |
284 | subdirs.add(os.path.dirname(f)) |
|
284 | subdirs.add(os.path.dirname(f)) | |
285 | subdirprogress = ui.makeprogress(_('checking'), unit=_('manifests'), |
|
285 | subdirprogress = ui.makeprogress(_('checking'), unit=_('manifests'), | |
286 | total=len(subdirs)) |
|
286 | total=len(subdirs)) | |
287 |
|
287 | |||
288 | for subdir, linkrevs in subdirnodes.iteritems(): |
|
288 | for subdir, linkrevs in subdirnodes.iteritems(): | |
289 | subdirfilenodes = self._verifymanifest(linkrevs, subdir, storefiles, |
|
289 | subdirfilenodes = self._verifymanifest(linkrevs, subdir, storefiles, | |
290 | subdirprogress) |
|
290 | subdirprogress) | |
291 | for f, onefilenodes in subdirfilenodes.iteritems(): |
|
291 | for f, onefilenodes in subdirfilenodes.iteritems(): | |
292 | filenodes.setdefault(f, {}).update(onefilenodes) |
|
292 | filenodes.setdefault(f, {}).update(onefilenodes) | |
293 |
|
293 | |||
294 | if not dir and subdirnodes: |
|
294 | if not dir and subdirnodes: | |
295 | subdirprogress.complete() |
|
295 | subdirprogress.complete() | |
296 | if self.warnorphanstorefiles: |
|
296 | if self.warnorphanstorefiles: | |
297 | for f in sorted(storefiles): |
|
297 | for f in sorted(storefiles): | |
298 | self._warn(_("warning: orphan data file '%s'") % f) |
|
298 | self._warn(_("warning: orphan data file '%s'") % f) | |
299 |
|
299 | |||
300 | return filenodes |
|
300 | return filenodes | |
301 |
|
301 | |||
302 | def _crosscheckfiles(self, filelinkrevs, filenodes): |
|
302 | def _crosscheckfiles(self, filelinkrevs, filenodes): | |
303 | repo = self.repo |
|
303 | repo = self.repo | |
304 | ui = self.ui |
|
304 | ui = self.ui | |
305 | ui.status(_("crosschecking files in changesets and manifests\n")) |
|
305 | ui.status(_("crosschecking files in changesets and manifests\n")) | |
306 |
|
306 | |||
307 | total = len(filelinkrevs) + len(filenodes) |
|
307 | total = len(filelinkrevs) + len(filenodes) | |
308 | progress = ui.makeprogress(_('crosschecking'), unit=_('files'), |
|
308 | progress = ui.makeprogress(_('crosschecking'), unit=_('files'), | |
309 | total=total) |
|
309 | total=total) | |
310 | if self.havemf: |
|
310 | if self.havemf: | |
311 | for f in sorted(filelinkrevs): |
|
311 | for f in sorted(filelinkrevs): | |
312 | progress.increment() |
|
312 | progress.increment() | |
313 | if f not in filenodes: |
|
313 | if f not in filenodes: | |
314 | lr = filelinkrevs[f][0] |
|
314 | lr = filelinkrevs[f][0] | |
315 | self._err(lr, _("in changeset but not in manifest"), f) |
|
315 | self._err(lr, _("in changeset but not in manifest"), f) | |
316 |
|
316 | |||
317 | if self.havecl: |
|
317 | if self.havecl: | |
318 | for f in sorted(filenodes): |
|
318 | for f in sorted(filenodes): | |
319 | progress.increment() |
|
319 | progress.increment() | |
320 | if f not in filelinkrevs: |
|
320 | if f not in filelinkrevs: | |
321 | try: |
|
321 | try: | |
322 | fl = repo.file(f) |
|
322 | fl = repo.file(f) | |
323 | lr = min([fl.linkrev(fl.rev(n)) for n in filenodes[f]]) |
|
323 | lr = min([fl.linkrev(fl.rev(n)) for n in filenodes[f]]) | |
324 | except Exception: |
|
324 | except Exception: | |
325 | lr = None |
|
325 | lr = None | |
326 | self._err(lr, _("in manifest but not in changeset"), f) |
|
326 | self._err(lr, _("in manifest but not in changeset"), f) | |
327 |
|
327 | |||
328 | progress.complete() |
|
328 | progress.complete() | |
329 |
|
329 | |||
330 | def _verifyfiles(self, filenodes, filelinkrevs): |
|
330 | def _verifyfiles(self, filenodes, filelinkrevs): | |
331 | repo = self.repo |
|
331 | repo = self.repo | |
332 | ui = self.ui |
|
332 | ui = self.ui | |
333 | lrugetctx = self.lrugetctx |
|
333 | lrugetctx = self.lrugetctx | |
334 | revlogv1 = self.revlogv1 |
|
334 | revlogv1 = self.revlogv1 | |
335 | havemf = self.havemf |
|
335 | havemf = self.havemf | |
336 | ui.status(_("checking files\n")) |
|
336 | ui.status(_("checking files\n")) | |
337 |
|
337 | |||
338 | storefiles = set() |
|
338 | storefiles = set() | |
339 | for f, f2, size in repo.store.datafiles(): |
|
339 | for f, f2, size in repo.store.datafiles(): | |
340 | if not f: |
|
340 | if not f: | |
341 | self._err(None, _("cannot decode filename '%s'") % f2) |
|
341 | self._err(None, _("cannot decode filename '%s'") % f2) | |
342 | elif (size > 0 or not revlogv1) and f.startswith('data/'): |
|
342 | elif (size > 0 or not revlogv1) and f.startswith('data/'): | |
343 | storefiles.add(_normpath(f)) |
|
343 | storefiles.add(_normpath(f)) | |
344 |
|
344 | |||
345 | state = { |
|
345 | state = { | |
346 | # TODO this assumes revlog storage for changelog. |
|
346 | # TODO this assumes revlog storage for changelog. | |
347 | 'expectedversion': self.repo.changelog.version & 0xFFFF, |
|
347 | 'expectedversion': self.repo.changelog.version & 0xFFFF, | |
348 | 'skipflags': self.skipflags, |
|
348 | 'skipflags': self.skipflags, | |
349 | # experimental config: censor.policy |
|
349 | # experimental config: censor.policy | |
350 | 'erroroncensored': ui.config('censor', 'policy') == 'abort', |
|
350 | 'erroroncensored': ui.config('censor', 'policy') == 'abort', | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | files = sorted(set(filenodes) | set(filelinkrevs)) |
|
353 | files = sorted(set(filenodes) | set(filelinkrevs)) | |
354 | revisions = 0 |
|
354 | revisions = 0 | |
355 | progress = ui.makeprogress(_('checking'), unit=_('files'), |
|
355 | progress = ui.makeprogress(_('checking'), unit=_('files'), | |
356 | total=len(files)) |
|
356 | total=len(files)) | |
357 | for i, f in enumerate(files): |
|
357 | for i, f in enumerate(files): | |
358 | progress.update(i, item=f) |
|
358 | progress.update(i, item=f) | |
359 | try: |
|
359 | try: | |
360 | linkrevs = filelinkrevs[f] |
|
360 | linkrevs = filelinkrevs[f] | |
361 | except KeyError: |
|
361 | except KeyError: | |
362 | # in manifest but not in changelog |
|
362 | # in manifest but not in changelog | |
363 | linkrevs = [] |
|
363 | linkrevs = [] | |
364 |
|
364 | |||
365 | if linkrevs: |
|
365 | if linkrevs: | |
366 | lr = linkrevs[0] |
|
366 | lr = linkrevs[0] | |
367 | else: |
|
367 | else: | |
368 | lr = None |
|
368 | lr = None | |
369 |
|
369 | |||
370 | try: |
|
370 | try: | |
371 | fl = repo.file(f) |
|
371 | fl = repo.file(f) | |
372 | except error.StorageError as e: |
|
372 | except error.StorageError as e: | |
373 | self._err(lr, _("broken revlog! (%s)") % e, f) |
|
373 | self._err(lr, _("broken revlog! (%s)") % e, f) | |
374 | continue |
|
374 | continue | |
375 |
|
375 | |||
376 | for ff in fl.files(): |
|
376 | for ff in fl.files(): | |
377 | try: |
|
377 | try: | |
378 | storefiles.remove(ff) |
|
378 | storefiles.remove(ff) | |
379 | except KeyError: |
|
379 | except KeyError: | |
380 | if self.warnorphanstorefiles: |
|
380 | if self.warnorphanstorefiles: | |
381 | self._warn(_(" warning: revlog '%s' not in fncache!") % |
|
381 | self._warn(_(" warning: revlog '%s' not in fncache!") % | |
382 | ff) |
|
382 | ff) | |
383 | self.fncachewarned = True |
|
383 | self.fncachewarned = True | |
384 |
|
384 | |||
385 | if not len(fl) and (self.havecl or self.havemf): |
|
385 | if not len(fl) and (self.havecl or self.havemf): | |
386 | self._err(lr, _("empty or missing %s") % f) |
|
386 | self._err(lr, _("empty or missing %s") % f) | |
387 | else: |
|
387 | else: | |
388 | # Guard against implementations not setting this. |
|
388 | # Guard against implementations not setting this. | |
389 | state['skipread'] = set() |
|
389 | state['skipread'] = set() | |
390 | for problem in fl.verifyintegrity(state): |
|
390 | for problem in fl.verifyintegrity(state): | |
391 | if problem.node is not None: |
|
391 | if problem.node is not None: | |
392 | linkrev = fl.linkrev(fl.rev(problem.node)) |
|
392 | linkrev = fl.linkrev(fl.rev(problem.node)) | |
393 | else: |
|
393 | else: | |
394 | linkrev = None |
|
394 | linkrev = None | |
395 |
|
395 | |||
396 | if problem.warning: |
|
396 | if problem.warning: | |
397 | self._warn(problem.warning) |
|
397 | self._warn(problem.warning) | |
398 | elif problem.error: |
|
398 | elif problem.error: | |
399 | self._err(linkrev if linkrev is not None else lr, |
|
399 | self._err(linkrev if linkrev is not None else lr, | |
400 | problem.error, f) |
|
400 | problem.error, f) | |
401 | else: |
|
401 | else: | |
402 | raise error.ProgrammingError( |
|
402 | raise error.ProgrammingError( | |
403 | 'problem instance does not set warning or error ' |
|
403 | 'problem instance does not set warning or error ' | |
404 | 'attribute: %s' % problem.msg) |
|
404 | 'attribute: %s' % problem.msg) | |
405 |
|
405 | |||
406 | seen = {} |
|
406 | seen = {} | |
407 | for i in fl: |
|
407 | for i in fl: | |
408 | revisions += 1 |
|
408 | revisions += 1 | |
409 | n = fl.node(i) |
|
409 | n = fl.node(i) | |
410 | lr = self.checkentry(fl, i, n, seen, linkrevs, f) |
|
410 | lr = self.checkentry(fl, i, n, seen, linkrevs, f) | |
411 | if f in filenodes: |
|
411 | if f in filenodes: | |
412 | if havemf and n not in filenodes[f]: |
|
412 | if havemf and n not in filenodes[f]: | |
413 | self._err(lr, _("%s not in manifests") % (short(n)), f) |
|
413 | self._err(lr, _("%s not in manifests") % (short(n)), f) | |
414 | else: |
|
414 | else: | |
415 | del filenodes[f][n] |
|
415 | del filenodes[f][n] | |
416 |
|
416 | |||
417 | if n in state['skipread']: |
|
417 | if n in state['skipread']: | |
418 | continue |
|
418 | continue | |
419 |
|
419 | |||
420 | # check renames |
|
420 | # check renames | |
421 | try: |
|
421 | try: | |
422 | # This requires resolving fulltext (at least on revlogs). We |
|
422 | # This requires resolving fulltext (at least on revlogs). We | |
423 | # may want ``verifyintegrity()`` to pass a set of nodes with |
|
423 | # may want ``verifyintegrity()`` to pass a set of nodes with | |
424 | # rename metadata as an optimization. |
|
424 | # rename metadata as an optimization. | |
425 | rp = fl.renamed(n) |
|
425 | rp = fl.renamed(n) | |
426 | if rp: |
|
426 | if rp: | |
427 | if lr is not None and ui.verbose: |
|
427 | if lr is not None and ui.verbose: | |
428 | ctx = lrugetctx(lr) |
|
428 | ctx = lrugetctx(lr) | |
429 | if not any(rp[0] in pctx for pctx in ctx.parents()): |
|
429 | if not any(rp[0] in pctx for pctx in ctx.parents()): | |
430 | self._warn(_("warning: copy source of '%s' not" |
|
430 | self._warn(_("warning: copy source of '%s' not" | |
431 | " in parents of %s") % (f, ctx)) |
|
431 | " in parents of %s") % (f, ctx)) | |
432 | fl2 = repo.file(rp[0]) |
|
432 | fl2 = repo.file(rp[0]) | |
433 | if not len(fl2): |
|
433 | if not len(fl2): | |
434 | self._err(lr, |
|
434 | self._err(lr, | |
435 | _("empty or missing copy source revlog " |
|
435 | _("empty or missing copy source revlog " | |
436 | "%s:%s") % (rp[0], |
|
436 | "%s:%s") % (rp[0], | |
437 | short(rp[1])), |
|
437 | short(rp[1])), | |
438 | f) |
|
438 | f) | |
439 | elif rp[1] == nullid: |
|
439 | elif rp[1] == nullid: | |
440 | ui.note(_("warning: %s@%s: copy source" |
|
440 | ui.note(_("warning: %s@%s: copy source" | |
441 | " revision is nullid %s:%s\n") |
|
441 | " revision is nullid %s:%s\n") | |
442 | % (f, lr, rp[0], short(rp[1]))) |
|
442 | % (f, lr, rp[0], short(rp[1]))) | |
443 | else: |
|
443 | else: | |
444 | fl2.rev(rp[1]) |
|
444 | fl2.rev(rp[1]) | |
445 | except Exception as inst: |
|
445 | except Exception as inst: | |
446 |
self.exc(lr, _("checking rename of %s") % short(n), |
|
446 | self._exc(lr, _("checking rename of %s") % short(n), | |
|
447 | inst, f) | |||
447 |
|
448 | |||
448 | # cross-check |
|
449 | # cross-check | |
449 | if f in filenodes: |
|
450 | if f in filenodes: | |
450 | fns = [(v, k) for k, v in filenodes[f].iteritems()] |
|
451 | fns = [(v, k) for k, v in filenodes[f].iteritems()] | |
451 | for lr, node in sorted(fns): |
|
452 | for lr, node in sorted(fns): | |
452 | self._err(lr, _("manifest refers to unknown revision %s") % |
|
453 | self._err(lr, _("manifest refers to unknown revision %s") % | |
453 | short(node), f) |
|
454 | short(node), f) | |
454 | progress.complete() |
|
455 | progress.complete() | |
455 |
|
456 | |||
456 | if self.warnorphanstorefiles: |
|
457 | if self.warnorphanstorefiles: | |
457 | for f in sorted(storefiles): |
|
458 | for f in sorted(storefiles): | |
458 | self._warn(_("warning: orphan data file '%s'") % f) |
|
459 | self._warn(_("warning: orphan data file '%s'") % f) | |
459 |
|
460 | |||
460 | return len(files), revisions |
|
461 | return len(files), revisions |
General Comments 0
You need to be logged in to leave comments.
Login now