Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/verify.py @ 41876:9e737ca539f6
verify: make `checkentry` a private method
This method is for internal use only.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 06 Mar 2019 12:20:50 +0100 |
parents | 00c9fde75c1a |
children | 08d977451f26 |
rev | line source |
---|---|
2778 | 1 # verify.py - repository integrity checking for Mercurial |
2 # | |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4395
diff
changeset
|
3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
2778 | 4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
2778 | 7 |
25991
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
8 from __future__ import absolute_import |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
9 |
17860
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
10 import os |
25991
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
11 |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
12 from .i18n import _ |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
13 from .node import ( |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
14 nullid, |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
15 short, |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
16 ) |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
17 |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
18 from . import ( |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
19 error, |
35585
35fb3367f72d
py3: use pycompat.bytestr() instead of str()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33499
diff
changeset
|
20 pycompat, |
25991
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
21 revlog, |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
22 util, |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
23 ) |
2778 | 24 |
25 def verify(repo): | |
27849
900d36a3e4dd
with: use context manager in verify
Bryan O'Sullivan <bryano@fb.com>
parents:
27695
diff
changeset
|
26 with repo.lock(): |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
27 return verifier(repo).verify() |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
28 |
17860
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
29 def _normpath(f): |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
30 # under hg < 2.4, convert didn't sanitize paths properly, so a |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
31 # converted repo may contain repeated slashes |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
32 while '//' in f: |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
33 f = f.replace('//', '/') |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
34 return f |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
35 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
36 class verifier(object): |
39943
fec944719324
narrow: move support for `hg verify` into core
Martin von Zweigbergk <martinvonz@google.com>
parents:
39877
diff
changeset
|
37 def __init__(self, repo): |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
38 self.repo = repo.unfiltered() |
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
39 self.ui = repo.ui |
39943
fec944719324
narrow: move support for `hg verify` into core
Martin von Zweigbergk <martinvonz@google.com>
parents:
39877
diff
changeset
|
40 self.match = repo.narrowmatch() |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
41 self.badrevs = set() |
27453
8462d7f2c4fe
verify: clean up weird error/warning lists
Matt Mackall <mpm@selenic.com>
parents:
27450
diff
changeset
|
42 self.errors = 0 |
8462d7f2c4fe
verify: clean up weird error/warning lists
Matt Mackall <mpm@selenic.com>
parents:
27450
diff
changeset
|
43 self.warnings = 0 |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
44 self.havecl = len(repo.changelog) > 0 |
39272
73cf21b2e8a6
manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38403
diff
changeset
|
45 self.havemf = len(repo.manifestlog.getstorage(b'')) > 0 |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
46 self.revlogv1 = repo.changelog.version != revlog.REVLOGV0 |
37302
00f18dd1d3d6
verify: remove dependence on repo.changectx()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36606
diff
changeset
|
47 self.lrugetctx = util.lrucachefunc(repo.__getitem__) |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
48 self.refersmf = False |
27445
cc178057ab49
verify: move fncachewarned up to a class variable
Durham Goode <durham@fb.com>
parents:
27444
diff
changeset
|
49 self.fncachewarned = False |
32328
a2ab9ebcd85b
verify: add a config option to skip certain flag processors
Jun Wu <quark@fb.com>
parents:
32290
diff
changeset
|
50 # developer config: verify.skipflags |
a2ab9ebcd85b
verify: add a config option to skip certain flag processors
Jun Wu <quark@fb.com>
parents:
32290
diff
changeset
|
51 self.skipflags = repo.ui.configint('verify', 'skipflags') |
37417
76d2115cb817
verify: allow suppressing warnings about extra files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37410
diff
changeset
|
52 self.warnorphanstorefiles = True |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
53 |
41867
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
54 def _warn(self, msg): |
41866
a58748300e61
verify: document the `warn` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
40437
diff
changeset
|
55 """record a "warning" level issue""" |
27446
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
56 self.ui.warn(msg + "\n") |
27453
8462d7f2c4fe
verify: clean up weird error/warning lists
Matt Mackall <mpm@selenic.com>
parents:
27450
diff
changeset
|
57 self.warnings += 1 |
27446
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
58 |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
59 def _err(self, linkrev, msg, filename=None): |
41868
9534f3cb6b6c
verify: document the `err` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41867
diff
changeset
|
60 """record a "error" level issue""" |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
61 if linkrev is not None: |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
62 self.badrevs.add(linkrev) |
36223
acc8e6e52af6
py3: use "%d" to convert integers to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35585
diff
changeset
|
63 linkrev = "%d" % linkrev |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
64 else: |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
65 linkrev = '?' |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
66 msg = "%s: %s" % (linkrev, msg) |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
67 if filename: |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
68 msg = "%s@%s" % (filename, msg) |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
69 self.ui.warn(" " + msg + "\n") |
27453
8462d7f2c4fe
verify: clean up weird error/warning lists
Matt Mackall <mpm@selenic.com>
parents:
27450
diff
changeset
|
70 self.errors += 1 |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
71 |
41871
cfe08588d711
verify: make the `exc` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41870
diff
changeset
|
72 def _exc(self, linkrev, msg, inst, filename=None): |
41870
5df8475c5343
verify: document the `exc` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41869
diff
changeset
|
73 """record exception raised during the verify process""" |
36606
d85ef895d5f6
verify: fix exception formatting bug in Python 3
Augie Fackler <augie@google.com>
parents:
36372
diff
changeset
|
74 fmsg = pycompat.bytestr(inst) |
d85ef895d5f6
verify: fix exception formatting bug in Python 3
Augie Fackler <augie@google.com>
parents:
36372
diff
changeset
|
75 if not fmsg: |
d85ef895d5f6
verify: fix exception formatting bug in Python 3
Augie Fackler <augie@google.com>
parents:
36372
diff
changeset
|
76 fmsg = pycompat.byterepr(inst) |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
77 self._err(linkrev, "%s: %s" % (msg, fmsg), filename) |
27448
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
78 |
27642
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
79 def checklog(self, obj, name, linkrev): |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
80 if not len(obj) and (self.havecl or self.havemf): |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
81 self._err(linkrev, _("empty or missing %s") % name) |
27642
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
82 return |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
83 |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
84 d = obj.checksize() |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
85 if d[0]: |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
86 self.err(None, _("data length off by %d bytes") % d[0], name) |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
87 if d[1]: |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
88 self.err(None, _("index contains %d extra bytes") % d[1], name) |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
89 |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
90 if obj.version != revlog.REVLOGV0: |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
91 if not self.revlogv1: |
41867
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
92 self._warn(_("warning: `%s' uses revlog format 1") % name) |
27642
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
93 elif self.revlogv1: |
41867
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
94 self._warn(_("warning: `%s' uses revlog format 0") % name) |
27642
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
95 |
41876
9e737ca539f6
verify: make `checkentry` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41875
diff
changeset
|
96 def _checkentry(self, obj, i, node, seen, linkrevs, f): |
41875
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
97 """verify a single revlog entry |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
98 |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
99 arguments are: |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
100 - obj: the source revlog |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
101 - i: the revision number |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
102 - node: the revision node id |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
103 - seen: nodes previously seen for this revlog |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
104 - linkrevs: [changelog-revisions] introducing "node" |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
105 - f: string label ("changelog", "manifest", or filename) |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
106 |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
107 Performs the following checks: |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
108 - linkrev points to an existing changelog revision, |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
109 - linkrev points to a changelog revision that introduces this revision, |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
110 - linkrev points to the lowest of these changesets, |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
111 - both parents exist in the revlog, |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
112 - the revision is not duplicated. |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
113 |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
114 Return the linkrev of the revision (or None for changelog's revisions). |
00c9fde75c1a
verify: document the `checkentry` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41874
diff
changeset
|
115 """ |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
116 lr = obj.linkrev(obj.rev(node)) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
117 if lr < 0 or (self.havecl and lr not in linkrevs): |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
118 if lr < 0 or lr >= len(self.repo.changelog): |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
119 msg = _("rev %d points to nonexistent changeset %d") |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
120 else: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
121 msg = _("rev %d points to unexpected changeset %d") |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
122 self._err(None, msg % (i, lr), f) |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
123 if linkrevs: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
124 if f and len(linkrevs) > 1: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
125 try: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
126 # attempt to filter down to real linkrevs |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
127 linkrevs = [l for l in linkrevs |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
128 if self.lrugetctx(l)[f].filenode() == node] |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
129 except Exception: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
130 pass |
41867
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
131 self._warn(_(" (expected %s)") % " ".join |
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
132 (map(pycompat.bytestr, linkrevs))) |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
133 lr = None # can't be trusted |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
134 |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
135 try: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
136 p1, p2 = obj.parents(node) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
137 if p1 not in seen and p1 != nullid: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
138 self._err(lr, _("unknown parent 1 %s of %s") % |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
139 (short(p1), short(node)), f) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
140 if p2 not in seen and p2 != nullid: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
141 self._err(lr, _("unknown parent 2 %s of %s") % |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
142 (short(p2), short(node)), f) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
143 except Exception as inst: |
41871
cfe08588d711
verify: make the `exc` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41870
diff
changeset
|
144 self._exc(lr, _("checking parents of %s") % short(node), inst, f) |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
145 |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
146 if node in seen: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
147 self._err(lr, _("duplicate revision %d (%d)") % (i, seen[node]), f) |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
148 seen[node] = i |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
149 return lr |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
150 |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
151 def verify(self): |
41872
e8c4a9f5b986
verify: minimal documentation for `verifier.verify`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41871
diff
changeset
|
152 """verify the content of the Mercurial repository |
e8c4a9f5b986
verify: minimal documentation for `verifier.verify`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41871
diff
changeset
|
153 |
e8c4a9f5b986
verify: minimal documentation for `verifier.verify`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41871
diff
changeset
|
154 This method run all verifications, displaying issues as they are found. |
e8c4a9f5b986
verify: minimal documentation for `verifier.verify`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41871
diff
changeset
|
155 |
41873
567892b4306c
verify: explicitly return 0 if no error are encountered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41872
diff
changeset
|
156 return 1 if any error have been encountered, 0 otherwise.""" |
41874
4da2261e949b
verify: add some inline documentation to the top level `verify` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41873
diff
changeset
|
157 # initial validation and generic report |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
158 repo = self.repo |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
159 ui = repo.ui |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
160 if not repo.url().startswith('file:'): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
161 raise error.Abort(_("cannot verify bundle or remote repos")) |
6752
e79a8f36c2a5
verify: lots of refactoring
Matt Mackall <mpm@selenic.com>
parents:
6751
diff
changeset
|
162 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
163 if os.path.exists(repo.sjoin("journal")): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
164 ui.warn(_("abandoned transaction found - run hg recover\n")) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
165 |
27648
e72e669dd51f
verify: get rid of some unnecessary local variables
Durham Goode <durham@fb.com>
parents:
27647
diff
changeset
|
166 if ui.verbose or not self.revlogv1: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
167 ui.status(_("repository uses revlog format %d\n") % |
27648
e72e669dd51f
verify: get rid of some unnecessary local variables
Durham Goode <durham@fb.com>
parents:
27647
diff
changeset
|
168 (self.revlogv1 and 1 or 0)) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
169 |
41874
4da2261e949b
verify: add some inline documentation to the top level `verify` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41873
diff
changeset
|
170 # data verification |
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
171 mflinkrevs, filelinkrevs = self._verifychangelog() |
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
172 filenodes = self._verifymanifest(mflinkrevs) |
28111
06205989264b
verify: move cross-checking of changeset/manifest out of _crosscheckfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28007
diff
changeset
|
173 del mflinkrevs |
06205989264b
verify: move cross-checking of changeset/manifest out of _crosscheckfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28007
diff
changeset
|
174 self._crosscheckfiles(filelinkrevs, filenodes) |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
175 totalfiles, filerevisions = self._verifyfiles(filenodes, filelinkrevs) |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
176 |
41874
4da2261e949b
verify: add some inline documentation to the top level `verify` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41873
diff
changeset
|
177 # final report |
39506
f1186c292d03
verify: make output less confusing (issue5924)
Meirambek Omyrzak <meirambek77@gmail.com>
parents:
39272
diff
changeset
|
178 ui.status(_("checked %d changesets with %d changes to %d files\n") % |
f1186c292d03
verify: make output less confusing (issue5924)
Meirambek Omyrzak <meirambek77@gmail.com>
parents:
39272
diff
changeset
|
179 (len(repo.changelog), filerevisions, totalfiles)) |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
180 if self.warnings: |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
181 ui.warn(_("%d warnings encountered!\n") % self.warnings) |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
182 if self.fncachewarned: |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
183 ui.warn(_('hint: run "hg debugrebuildfncache" to recover from ' |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
184 'corrupt fncache\n')) |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
185 if self.errors: |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
186 ui.warn(_("%d integrity errors encountered!\n") % self.errors) |
27648
e72e669dd51f
verify: get rid of some unnecessary local variables
Durham Goode <durham@fb.com>
parents:
27647
diff
changeset
|
187 if self.badrevs: |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
188 ui.warn(_("(first damaged changeset appears to be %d)\n") |
27648
e72e669dd51f
verify: get rid of some unnecessary local variables
Durham Goode <durham@fb.com>
parents:
27647
diff
changeset
|
189 % min(self.badrevs)) |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
190 return 1 |
41873
567892b4306c
verify: explicitly return 0 if no error are encountered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41872
diff
changeset
|
191 return 0 |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
192 |
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
193 def _verifychangelog(self): |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
194 ui = self.ui |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
195 repo = self.repo |
30900
5249b6470de9
verify: replace _validpath() by matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
30403
diff
changeset
|
196 match = self.match |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
197 cl = repo.changelog |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
198 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
199 ui.status(_("checking changesets\n")) |
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
200 mflinkrevs = {} |
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
201 filelinkrevs = {} |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
202 seen = {} |
27642
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
203 self.checklog(cl, "changelog", 0) |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
204 progress = ui.makeprogress(_('checking'), unit=_('changesets'), |
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
205 total=len(repo)) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
206 for i in repo: |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
207 progress.update(i) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
208 n = cl.node(i) |
41876
9e737ca539f6
verify: make `checkentry` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41875
diff
changeset
|
209 self._checkentry(cl, i, n, seen, [i], "changelog") |
2778 | 210 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
211 try: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
212 changes = cl.read(n) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
213 if changes[0] != nullid: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
214 mflinkrevs.setdefault(changes[0], []).append(i) |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
215 self.refersmf = True |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
216 for f in changes[3]: |
30900
5249b6470de9
verify: replace _validpath() by matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
30403
diff
changeset
|
217 if match(f): |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
218 filelinkrevs.setdefault(_normpath(f), []).append(i) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
219 except Exception as inst: |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
220 self.refersmf = True |
41871
cfe08588d711
verify: make the `exc` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41870
diff
changeset
|
221 self._exc(i, _("unpacking changeset %s") % short(n), inst) |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
222 progress.complete() |
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
223 return mflinkrevs, filelinkrevs |
2778 | 224 |
28205
53f42c8d5f71
verify: show progress while verifying dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28204
diff
changeset
|
225 def _verifymanifest(self, mflinkrevs, dir="", storefiles=None, |
38402
0ddbe03c5aaa
verify: use progress helper for subdirectory progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
37417
diff
changeset
|
226 subdirprogress=None): |
27646
8f43793382c6
verify: move manifest verification to its own function
Durham Goode <durham@fb.com>
parents:
27645
diff
changeset
|
227 repo = self.repo |
8f43793382c6
verify: move manifest verification to its own function
Durham Goode <durham@fb.com>
parents:
27645
diff
changeset
|
228 ui = self.ui |
30900
5249b6470de9
verify: replace _validpath() by matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
30403
diff
changeset
|
229 match = self.match |
30309
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
28467
diff
changeset
|
230 mfl = self.repo.manifestlog |
39272
73cf21b2e8a6
manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38403
diff
changeset
|
231 mf = mfl.getstorage(dir) |
27646
8f43793382c6
verify: move manifest verification to its own function
Durham Goode <durham@fb.com>
parents:
27645
diff
changeset
|
232 |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
233 if not dir: |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
234 self.ui.status(_("checking manifests\n")) |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
235 |
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
236 filenodes = {} |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
237 subdirnodes = {} |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
238 seen = {} |
28115
bd279da57e4b
verify: extract "manifest" constant into variable
Martin von Zweigbergk <martinvonz@google.com>
parents:
28114
diff
changeset
|
239 label = "manifest" |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
240 if dir: |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
241 label = dir |
28204
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
242 revlogfiles = mf.files() |
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
243 storefiles.difference_update(revlogfiles) |
38402
0ddbe03c5aaa
verify: use progress helper for subdirectory progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
37417
diff
changeset
|
244 if subdirprogress: # should be true since we're in a subdirectory |
0ddbe03c5aaa
verify: use progress helper for subdirectory progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
37417
diff
changeset
|
245 subdirprogress.increment() |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
246 if self.refersmf: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
247 # Do not check manifest if there are only changelog entries with |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
248 # null manifests. |
28115
bd279da57e4b
verify: extract "manifest" constant into variable
Martin von Zweigbergk <martinvonz@google.com>
parents:
28114
diff
changeset
|
249 self.checklog(mf, label, 0) |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
250 progress = ui.makeprogress(_('checking'), unit=_('manifests'), |
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
251 total=len(mf)) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
252 for i in mf: |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
253 if not dir: |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
254 progress.update(i) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
255 n = mf.node(i) |
41876
9e737ca539f6
verify: make `checkentry` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41875
diff
changeset
|
256 lr = self._checkentry(mf, i, n, seen, mflinkrevs.get(n, []), label) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
257 if n in mflinkrevs: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
258 del mflinkrevs[n] |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
259 elif dir: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
260 self._err(lr, _("%s not in parent-directory manifest") % |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
261 short(n), label) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
262 else: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
263 self._err(lr, _("%s not in changesets") % short(n), label) |
2778 | 264 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
265 try: |
30309
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
28467
diff
changeset
|
266 mfdelta = mfl.get(dir, n).readdelta(shallow=True) |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
28467
diff
changeset
|
267 for f, fn, fl in mfdelta.iterentries(): |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
268 if not f: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
269 self._err(lr, _("entry without name in manifest")) |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
270 elif f == "/dev/null": # ignore this in very old repos |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
271 continue |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
272 fullpath = dir + _normpath(f) |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
273 if fl == 't': |
30900
5249b6470de9
verify: replace _validpath() by matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
30403
diff
changeset
|
274 if not match.visitdir(fullpath): |
5249b6470de9
verify: replace _validpath() by matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
30403
diff
changeset
|
275 continue |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
276 subdirnodes.setdefault(fullpath + '/', {}).setdefault( |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
277 fn, []).append(lr) |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
278 else: |
30900
5249b6470de9
verify: replace _validpath() by matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
30403
diff
changeset
|
279 if not match(fullpath): |
5249b6470de9
verify: replace _validpath() by matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
30403
diff
changeset
|
280 continue |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
281 filenodes.setdefault(fullpath, {}).setdefault(fn, lr) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
282 except Exception as inst: |
41871
cfe08588d711
verify: make the `exc` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41870
diff
changeset
|
283 self._exc(lr, _("reading delta %s") % short(n), inst, label) |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
284 if not dir: |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
285 progress.complete() |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
286 |
28111
06205989264b
verify: move cross-checking of changeset/manifest out of _crosscheckfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28007
diff
changeset
|
287 if self.havemf: |
06205989264b
verify: move cross-checking of changeset/manifest out of _crosscheckfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28007
diff
changeset
|
288 for c, m in sorted([(c, m) for m in mflinkrevs |
06205989264b
verify: move cross-checking of changeset/manifest out of _crosscheckfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28007
diff
changeset
|
289 for c in mflinkrevs[m]]): |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
290 if dir: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
291 self._err(c, _("parent-directory manifest refers to unknown" |
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
292 " revision %s") % short(m), label) |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
293 else: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
294 self._err(c, _("changeset refers to unknown revision %s") % |
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
295 short(m), label) |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
296 |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
297 if not dir and subdirnodes: |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
298 self.ui.status(_("checking directory manifests\n")) |
28204
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
299 storefiles = set() |
28205
53f42c8d5f71
verify: show progress while verifying dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28204
diff
changeset
|
300 subdirs = set() |
28204
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
301 revlogv1 = self.revlogv1 |
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
302 for f, f2, size in repo.store.datafiles(): |
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
303 if not f: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
304 self._err(None, _("cannot decode filename '%s'") % f2) |
28204
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
305 elif (size > 0 or not revlogv1) and f.startswith('meta/'): |
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
306 storefiles.add(_normpath(f)) |
28205
53f42c8d5f71
verify: show progress while verifying dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28204
diff
changeset
|
307 subdirs.add(os.path.dirname(f)) |
38402
0ddbe03c5aaa
verify: use progress helper for subdirectory progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
37417
diff
changeset
|
308 subdirprogress = ui.makeprogress(_('checking'), unit=_('manifests'), |
0ddbe03c5aaa
verify: use progress helper for subdirectory progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
37417
diff
changeset
|
309 total=len(subdirs)) |
28204
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
310 |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
311 for subdir, linkrevs in subdirnodes.iteritems(): |
28205
53f42c8d5f71
verify: show progress while verifying dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28204
diff
changeset
|
312 subdirfilenodes = self._verifymanifest(linkrevs, subdir, storefiles, |
38402
0ddbe03c5aaa
verify: use progress helper for subdirectory progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
37417
diff
changeset
|
313 subdirprogress) |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
314 for f, onefilenodes in subdirfilenodes.iteritems(): |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28115
diff
changeset
|
315 filenodes.setdefault(f, {}).update(onefilenodes) |
28111
06205989264b
verify: move cross-checking of changeset/manifest out of _crosscheckfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28007
diff
changeset
|
316 |
28204
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
317 if not dir and subdirnodes: |
38402
0ddbe03c5aaa
verify: use progress helper for subdirectory progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
37417
diff
changeset
|
318 subdirprogress.complete() |
37417
76d2115cb817
verify: allow suppressing warnings about extra files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37410
diff
changeset
|
319 if self.warnorphanstorefiles: |
76d2115cb817
verify: allow suppressing warnings about extra files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37410
diff
changeset
|
320 for f in sorted(storefiles): |
41867
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
321 self._warn(_("warning: orphan data file '%s'") % f) |
28204
962921c330b0
verify: check for orphaned dirlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
322 |
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
323 return filenodes |
27645
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
324 |
28111
06205989264b
verify: move cross-checking of changeset/manifest out of _crosscheckfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28007
diff
changeset
|
325 def _crosscheckfiles(self, filelinkrevs, filenodes): |
27645
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
326 repo = self.repo |
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
327 ui = self.ui |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
328 ui.status(_("crosschecking files in changesets and manifests\n")) |
2778 | 329 |
28111
06205989264b
verify: move cross-checking of changeset/manifest out of _crosscheckfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28007
diff
changeset
|
330 total = len(filelinkrevs) + len(filenodes) |
40437
d2ff0af6e959
verify: provide unit to ui.makeprogress()
Anton Shestakov <av6@dwimlabs.net>
parents:
39943
diff
changeset
|
331 progress = ui.makeprogress(_('crosschecking'), unit=_('files'), |
d2ff0af6e959
verify: provide unit to ui.makeprogress()
Anton Shestakov <av6@dwimlabs.net>
parents:
39943
diff
changeset
|
332 total=total) |
27645
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
333 if self.havemf: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
334 for f in sorted(filelinkrevs): |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
335 progress.increment() |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
336 if f not in filenodes: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
337 lr = filelinkrevs[f][0] |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
338 self._err(lr, _("in changeset but not in manifest"), f) |
6892
dab95717058d
verify: check repo.store
Adrian Buehlmann <adrian@cadifra.com>
parents:
6889
diff
changeset
|
339 |
27645
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
340 if self.havecl: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
341 for f in sorted(filenodes): |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
342 progress.increment() |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
343 if f not in filelinkrevs: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
344 try: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
345 fl = repo.file(f) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
346 lr = min([fl.linkrev(fl.rev(n)) for n in filenodes[f]]) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
347 except Exception: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
348 lr = None |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
349 self._err(lr, _("in manifest but not in changeset"), f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
350 |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
351 progress.complete() |
8291
f5c1a9094e41
verify: avoid exception on missing file revlog
Henrik Stuart <hg@hstuart.dk>
parents:
8225
diff
changeset
|
352 |
27644
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
353 def _verifyfiles(self, filenodes, filelinkrevs): |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
354 repo = self.repo |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
355 ui = self.ui |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
356 lrugetctx = self.lrugetctx |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
357 revlogv1 = self.revlogv1 |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
358 havemf = self.havemf |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
359 ui.status(_("checking files\n")) |
8291
f5c1a9094e41
verify: avoid exception on missing file revlog
Henrik Stuart <hg@hstuart.dk>
parents:
8225
diff
changeset
|
360 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
361 storefiles = set() |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
362 for f, f2, size in repo.store.datafiles(): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
363 if not f: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
364 self._err(None, _("cannot decode filename '%s'") % f2) |
28007
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
27964
diff
changeset
|
365 elif (size > 0 or not revlogv1) and f.startswith('data/'): |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
366 storefiles.add(_normpath(f)) |
6892
dab95717058d
verify: check repo.store
Adrian Buehlmann <adrian@cadifra.com>
parents:
6889
diff
changeset
|
367 |
39847
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
368 state = { |
39850
e6d3d39cc1c7
revlog: use proper version comparison during verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39847
diff
changeset
|
369 # TODO this assumes revlog storage for changelog. |
39877
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
370 'expectedversion': self.repo.changelog.version & 0xFFFF, |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
371 'skipflags': self.skipflags, |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
372 # experimental config: censor.policy |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
373 'erroroncensored': ui.config('censor', 'policy') == 'abort', |
39847
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
374 } |
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
375 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
376 files = sorted(set(filenodes) | set(filelinkrevs)) |
27644
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
377 revisions = 0 |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
378 progress = ui.makeprogress(_('checking'), unit=_('files'), |
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
379 total=len(files)) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
380 for i, f in enumerate(files): |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
381 progress.update(i, item=f) |
6892
dab95717058d
verify: check repo.store
Adrian Buehlmann <adrian@cadifra.com>
parents:
6889
diff
changeset
|
382 try: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
383 linkrevs = filelinkrevs[f] |
6892
dab95717058d
verify: check repo.store
Adrian Buehlmann <adrian@cadifra.com>
parents:
6889
diff
changeset
|
384 except KeyError: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
385 # in manifest but not in changelog |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
386 linkrevs = [] |
2778 | 387 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
388 if linkrevs: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
389 lr = linkrevs[0] |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
390 else: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
391 lr = None |
2778 | 392 |
3744
d626fc9e3985
verify: add rename link checking
Matt Mackall <mpm@selenic.com>
parents:
3473
diff
changeset
|
393 try: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
394 fl = repo.file(f) |
39793
b63dee7bd0d9
global: replace most uses of RevlogError with StorageError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39506
diff
changeset
|
395 except error.StorageError as e: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
396 self._err(lr, _("broken revlog! (%s)") % e, f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
397 continue |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
398 |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
399 for ff in fl.files(): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
400 try: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
401 storefiles.remove(ff) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
402 except KeyError: |
37417
76d2115cb817
verify: allow suppressing warnings about extra files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37410
diff
changeset
|
403 if self.warnorphanstorefiles: |
41867
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
404 self._warn(_(" warning: revlog '%s' not in fncache!") % |
37417
76d2115cb817
verify: allow suppressing warnings about extra files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37410
diff
changeset
|
405 ff) |
76d2115cb817
verify: allow suppressing warnings about extra files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37410
diff
changeset
|
406 self.fncachewarned = True |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
407 |
39847
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
408 if not len(fl) and (self.havecl or self.havemf): |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
409 self._err(lr, _("empty or missing %s") % f) |
39847
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
410 else: |
39877
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
411 # Guard against implementations not setting this. |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
412 state['skipread'] = set() |
39847
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
413 for problem in fl.verifyintegrity(state): |
39877
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
414 if problem.node is not None: |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
415 linkrev = fl.linkrev(fl.rev(problem.node)) |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
416 else: |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
417 linkrev = None |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
418 |
39847
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
419 if problem.warning: |
41867
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
420 self._warn(problem.warning) |
39847
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
421 elif problem.error: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
422 self._err(linkrev if linkrev is not None else lr, |
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
423 problem.error, f) |
39847
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
424 else: |
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
425 raise error.ProgrammingError( |
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
426 'problem instance does not set warning or error ' |
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
427 'attribute: %s' % problem.msg) |
97986c9c69d3
verify: start to abstract file verification
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
428 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
429 seen = {} |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
430 for i in fl: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
431 revisions += 1 |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
432 n = fl.node(i) |
41876
9e737ca539f6
verify: make `checkentry` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41875
diff
changeset
|
433 lr = self._checkentry(fl, i, n, seen, linkrevs, f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
434 if f in filenodes: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
435 if havemf and n not in filenodes[f]: |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
436 self._err(lr, _("%s not in manifests") % (short(n)), f) |
6534
9b35a9f34675
verify: check copy source revlog and nodeid
Patrick Mezard <pmezard@gmail.com>
parents:
6211
diff
changeset
|
437 else: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
438 del filenodes[f][n] |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
439 |
39877
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
440 if n in state['skipread']: |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
441 continue |
3744
d626fc9e3985
verify: add rename link checking
Matt Mackall <mpm@selenic.com>
parents:
3473
diff
changeset
|
442 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
443 # check renames |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
444 try: |
39877
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
445 # This requires resolving fulltext (at least on revlogs). We |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
446 # may want ``verifyintegrity()`` to pass a set of nodes with |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
447 # rename metadata as an optimization. |
733db72f0f54
revlog: move revision verification out of verify
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39850
diff
changeset
|
448 rp = fl.renamed(n) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
449 if rp: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
450 if lr is not None and ui.verbose: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
451 ctx = lrugetctx(lr) |
36372
a4d41ba4ad23
verify: don't reimplement any()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36223
diff
changeset
|
452 if not any(rp[0] in pctx for pctx in ctx.parents()): |
41867
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
453 self._warn(_("warning: copy source of '%s' not" |
27446
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
454 " in parents of %s") % (f, ctx)) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
455 fl2 = repo.file(rp[0]) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
456 if not len(fl2): |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
457 self._err(lr, |
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
458 _("empty or missing copy source revlog " |
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
459 "%s:%s") % (rp[0], |
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
460 short(rp[1])), |
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
461 f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
462 elif rp[1] == nullid: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
463 ui.note(_("warning: %s@%s: copy source" |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
464 " revision is nullid %s:%s\n") |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
465 % (f, lr, rp[0], short(rp[1]))) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
466 else: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
467 fl2.rev(rp[1]) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
468 except Exception as inst: |
41871
cfe08588d711
verify: make the `exc` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41870
diff
changeset
|
469 self._exc(lr, _("checking rename of %s") % short(n), |
cfe08588d711
verify: make the `exc` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41870
diff
changeset
|
470 inst, f) |
6892
dab95717058d
verify: check repo.store
Adrian Buehlmann <adrian@cadifra.com>
parents:
6889
diff
changeset
|
471 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
472 # cross-check |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
473 if f in filenodes: |
30403
b667b78099eb
verify: avoid shadowing two variables with a list comprehension
Augie Fackler <augie@google.com>
parents:
30385
diff
changeset
|
474 fns = [(v, k) for k, v in filenodes[f].iteritems()] |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
475 for lr, node in sorted(fns): |
41869
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
476 self._err(lr, _("manifest refers to unknown revision %s") % |
7eaf4b1ac2a3
verify: make `err` a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41868
diff
changeset
|
477 short(node), f) |
38403
1249475f0bd6
verify: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38402
diff
changeset
|
478 progress.complete() |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
479 |
37417
76d2115cb817
verify: allow suppressing warnings about extra files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37410
diff
changeset
|
480 if self.warnorphanstorefiles: |
76d2115cb817
verify: allow suppressing warnings about extra files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37410
diff
changeset
|
481 for f in sorted(storefiles): |
41867
c66037fb1bc5
verify: make the `warn` method private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41866
diff
changeset
|
482 self._warn(_("warning: orphan data file '%s'") % f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
483 |
27644
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
484 return len(files), revisions |