author | Bryan O'Sullivan <bryano@fb.com> |
Fri, 15 Jan 2016 13:14:46 -0800 | |
changeset 27818 | 484895cc0f60 |
parent 27695 | fb0cc863d172 |
child 27849 | 900d36a3e4dd |
permissions | -rw-r--r-- |
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, |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
20 |
revlog, |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
21 |
util, |
d21d1774c73b
verify: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25846
diff
changeset
|
22 |
) |
2778 | 23 |
|
24 |
def verify(repo): |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
25 |
lock = repo.lock() |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
26 |
try: |
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 |
finally: |
8109
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7926
diff
changeset
|
29 |
lock.release() |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
30 |
|
17860
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
31 |
def _normpath(f): |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
32 |
# 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
|
33 |
# converted repo may contain repeated slashes |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
34 |
while '//' in f: |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
35 |
f = f.replace('//', '/') |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
36 |
return f |
a45b33f12627
verify: fix all doubled-slash sites (issue3665)
Bryan O'Sullivan <bryano@fb.com>
parents:
17851
diff
changeset
|
37 |
|
26900
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
38 |
def _validpath(repo, path): |
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
39 |
"""Returns False if a path should NOT be treated as part of a repo. |
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
40 |
|
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
41 |
For all in-core cases, this returns True, as we have no way for a |
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
42 |
path to be mentioned in the history but not actually be |
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
43 |
relevant. For narrow clones, this is important because many |
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
44 |
filelogs will be missing, and changelog entries may mention |
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
45 |
modified files that are outside the narrow scope. |
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
46 |
""" |
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
47 |
return True |
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
48 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
49 |
class verifier(object): |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
50 |
def __init__(self, repo): |
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
51 |
self.repo = repo.unfiltered() |
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
52 |
self.ui = repo.ui |
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
53 |
self.badrevs = set() |
27453
8462d7f2c4fe
verify: clean up weird error/warning lists
Matt Mackall <mpm@selenic.com>
parents:
27450
diff
changeset
|
54 |
self.errors = 0 |
8462d7f2c4fe
verify: clean up weird error/warning lists
Matt Mackall <mpm@selenic.com>
parents:
27450
diff
changeset
|
55 |
self.warnings = 0 |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
56 |
self.havecl = len(repo.changelog) > 0 |
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
57 |
self.havemf = len(repo.manifest) > 0 |
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
58 |
self.revlogv1 = repo.changelog.version != revlog.REVLOGV0 |
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
59 |
self.lrugetctx = util.lrucachefunc(repo.changectx) |
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
60 |
self.refersmf = False |
27445
cc178057ab49
verify: move fncachewarned up to a class variable
Durham Goode <durham@fb.com>
parents:
27444
diff
changeset
|
61 |
self.fncachewarned = False |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
62 |
|
27446
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
63 |
def warn(self, msg): |
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
64 |
self.ui.warn(msg + "\n") |
27453
8462d7f2c4fe
verify: clean up weird error/warning lists
Matt Mackall <mpm@selenic.com>
parents:
27450
diff
changeset
|
65 |
self.warnings += 1 |
27446
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
66 |
|
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
67 |
def err(self, linkrev, msg, filename=None): |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
68 |
if linkrev is not None: |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
69 |
self.badrevs.add(linkrev) |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
70 |
else: |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
71 |
linkrev = '?' |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
72 |
msg = "%s: %s" % (linkrev, msg) |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
73 |
if filename: |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
74 |
msg = "%s@%s" % (filename, msg) |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
75 |
self.ui.warn(" " + msg + "\n") |
27453
8462d7f2c4fe
verify: clean up weird error/warning lists
Matt Mackall <mpm@selenic.com>
parents:
27450
diff
changeset
|
76 |
self.errors += 1 |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
77 |
|
27448
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
78 |
def exc(self, linkrev, msg, inst, filename=None): |
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
79 |
if not str(inst): |
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
80 |
inst = repr(inst) |
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
81 |
self.err(linkrev, "%s: %s" % (msg, inst), filename) |
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
82 |
|
27642
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
83 |
def checklog(self, obj, name, linkrev): |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
84 |
if not len(obj) and (self.havecl or self.havemf): |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
85 |
self.err(linkrev, _("empty or missing %s") % name) |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
86 |
return |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
87 |
|
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
88 |
d = obj.checksize() |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
89 |
if d[0]: |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
90 |
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
|
91 |
if d[1]: |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
92 |
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
|
93 |
|
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
94 |
if obj.version != revlog.REVLOGV0: |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
95 |
if not self.revlogv1: |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
96 |
self.warn(_("warning: `%s' uses revlog format 1") % name) |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
97 |
elif self.revlogv1: |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
98 |
self.warn(_("warning: `%s' uses revlog format 0") % name) |
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
99 |
|
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
100 |
def checkentry(self, obj, i, node, seen, linkrevs, f): |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
101 |
lr = obj.linkrev(obj.rev(node)) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
else: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
106 |
msg = _("rev %d points to unexpected changeset %d") |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
107 |
self.err(None, msg % (i, lr), f) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
108 |
if linkrevs: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
109 |
if f and len(linkrevs) > 1: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
110 |
try: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
111 |
# 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
|
112 |
linkrevs = [l for l in linkrevs |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
113 |
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
|
114 |
except Exception: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
115 |
pass |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
116 |
self.warn(_(" (expected %s)") % " ".join(map(str, linkrevs))) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
117 |
lr = None # can't be trusted |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
118 |
|
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
119 |
try: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
120 |
p1, p2 = obj.parents(node) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
121 |
if p1 not in seen and p1 != nullid: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
122 |
self.err(lr, _("unknown parent 1 %s of %s") % |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
123 |
(short(p1), short(node)), f) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
124 |
if p2 not in seen and p2 != nullid: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
125 |
self.err(lr, _("unknown parent 2 %s of %s") % |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
126 |
(short(p2), short(node)), f) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
127 |
except Exception as inst: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
128 |
self.exc(lr, _("checking parents of %s") % short(node), inst, f) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
129 |
|
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
130 |
if node in seen: |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
131 |
self.err(lr, _("duplicate revision %d (%d)") % (i, seen[node]), f) |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
132 |
seen[node] = i |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
133 |
return lr |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
134 |
|
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
135 |
def verify(self): |
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
136 |
repo = self.repo |
27648
e72e669dd51f
verify: get rid of some unnecessary local variables
Durham Goode <durham@fb.com>
parents:
27647
diff
changeset
|
137 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
138 |
ui = repo.ui |
2778 | 139 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
140 |
if not repo.url().startswith('file:'): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
141 |
raise error.Abort(_("cannot verify bundle or remote repos")) |
6752
e79a8f36c2a5
verify: lots of refactoring
Matt Mackall <mpm@selenic.com>
parents:
6751
diff
changeset
|
142 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
143 |
if os.path.exists(repo.sjoin("journal")): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
144 |
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
|
145 |
|
27648
e72e669dd51f
verify: get rid of some unnecessary local variables
Durham Goode <durham@fb.com>
parents:
27647
diff
changeset
|
146 |
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
|
147 |
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
|
148 |
(self.revlogv1 and 1 or 0)) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
149 |
|
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
150 |
mflinkrevs, filelinkrevs = self._verifychangelog() |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
151 |
|
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
152 |
filenodes = self._verifymanifest(mflinkrevs) |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
153 |
|
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
154 |
self._crosscheckfiles(mflinkrevs, filelinkrevs, filenodes) |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
155 |
|
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
156 |
totalfiles, filerevisions = self._verifyfiles(filenodes, filelinkrevs) |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
157 |
|
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
158 |
ui.status(_("%d files, %d changesets, %d total revisions\n") % |
27648
e72e669dd51f
verify: get rid of some unnecessary local variables
Durham Goode <durham@fb.com>
parents:
27647
diff
changeset
|
159 |
(totalfiles, len(repo.changelog), filerevisions)) |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
160 |
if self.warnings: |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
161 |
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
|
162 |
if self.fncachewarned: |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
163 |
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
|
164 |
'corrupt fncache\n')) |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
165 |
if self.errors: |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
166 |
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
|
167 |
if self.badrevs: |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
168 |
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
|
169 |
% min(self.badrevs)) |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
170 |
return 1 |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
171 |
|
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
172 |
def _verifychangelog(self): |
27647
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
173 |
ui = self.ui |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
174 |
repo = self.repo |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
175 |
cl = repo.changelog |
2c2858f3c1bb
verify: move changelog verificaiton to its own function
Durham Goode <durham@fb.com>
parents:
27646
diff
changeset
|
176 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
177 |
ui.status(_("checking changesets\n")) |
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
178 |
mflinkrevs = {} |
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
179 |
filelinkrevs = {} |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
180 |
seen = {} |
27642
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
181 |
self.checklog(cl, "changelog", 0) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
182 |
total = len(repo) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
183 |
for i in repo: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
184 |
ui.progress(_('checking'), i, total=total, unit=_('changesets')) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
185 |
n = cl.node(i) |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
186 |
self.checkentry(cl, i, n, seen, [i], "changelog") |
2778 | 187 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
188 |
try: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
189 |
changes = cl.read(n) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
190 |
if changes[0] != nullid: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
191 |
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
|
192 |
self.refersmf = True |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
193 |
for f in changes[3]: |
26900
d1c741644d25
verify: add a hook that can let extensions manipulate file lists
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
194 |
if _validpath(repo, f): |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
195 |
filelinkrevs.setdefault(_normpath(f), []).append(i) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
196 |
except Exception as inst: |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
197 |
self.refersmf = True |
27448
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
198 |
self.exc(i, _("unpacking changeset %s") % short(n), inst) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
199 |
ui.progress(_('checking'), None) |
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
200 |
return mflinkrevs, filelinkrevs |
2778 | 201 |
|
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
202 |
def _verifymanifest(self, mflinkrevs): |
27646
8f43793382c6
verify: move manifest verification to its own function
Durham Goode <durham@fb.com>
parents:
27645
diff
changeset
|
203 |
repo = self.repo |
8f43793382c6
verify: move manifest verification to its own function
Durham Goode <durham@fb.com>
parents:
27645
diff
changeset
|
204 |
ui = self.ui |
8f43793382c6
verify: move manifest verification to its own function
Durham Goode <durham@fb.com>
parents:
27645
diff
changeset
|
205 |
mf = self.repo.manifest |
8f43793382c6
verify: move manifest verification to its own function
Durham Goode <durham@fb.com>
parents:
27645
diff
changeset
|
206 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
207 |
ui.status(_("checking manifests\n")) |
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
208 |
filenodes = {} |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
209 |
seen = {} |
27444
6647401858ab
verify: move widely used variables into class members
Durham Goode <durham@fb.com>
parents:
27443
diff
changeset
|
210 |
if self.refersmf: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
211 |
# 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
|
212 |
# null manifests. |
27642
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
213 |
self.checklog(mf, "manifest", 0) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
214 |
total = len(mf) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
215 |
for i in mf: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
216 |
ui.progress(_('checking'), i, total=total, unit=_('manifests')) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
217 |
n = mf.node(i) |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
218 |
lr = self.checkentry(mf, i, n, seen, mflinkrevs.get(n, []), |
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
219 |
"manifest") |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
220 |
if n in mflinkrevs: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
221 |
del mflinkrevs[n] |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
222 |
else: |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
223 |
self.err(lr, _("%s not in changesets") % short(n), "manifest") |
2778 | 224 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
225 |
try: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
226 |
for f, fn in mf.readdelta(n).iteritems(): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
227 |
if not f: |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
228 |
self.err(lr, _("file without name in manifest")) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
229 |
elif f != "/dev/null": # ignore this in very old repos |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
230 |
if _validpath(repo, f): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
231 |
filenodes.setdefault( |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
232 |
_normpath(f), {}).setdefault(fn, lr) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
233 |
except Exception as inst: |
27448
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
234 |
self.exc(lr, _("reading manifest delta %s") % short(n), inst) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
235 |
ui.progress(_('checking'), None) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
236 |
|
27695
fb0cc863d172
verify: replace "output parameters" by return values
Martin von Zweigbergk <martinvonz@google.com>
parents:
27648
diff
changeset
|
237 |
return filenodes |
27645
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
238 |
|
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
239 |
def _crosscheckfiles(self, mflinkrevs, filelinkrevs, filenodes): |
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
240 |
repo = self.repo |
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
241 |
ui = self.ui |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
242 |
ui.status(_("crosschecking files in changesets and manifests\n")) |
2778 | 243 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
244 |
total = len(mflinkrevs) + len(filelinkrevs) + len(filenodes) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
245 |
count = 0 |
27645
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
246 |
if self.havemf: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
247 |
for c, m in sorted([(c, m) for m in mflinkrevs |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
248 |
for c in mflinkrevs[m]]): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
249 |
count += 1 |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
250 |
if m == nullid: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
251 |
continue |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
252 |
ui.progress(_('crosschecking'), count, total=total) |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
253 |
self.err(c, _("changeset refers to unknown manifest %s") % |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
254 |
short(m)) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
255 |
mflinkrevs = None # del is bad here due to scope issues |
6752
e79a8f36c2a5
verify: lots of refactoring
Matt Mackall <mpm@selenic.com>
parents:
6751
diff
changeset
|
256 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
257 |
for f in sorted(filelinkrevs): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
258 |
count += 1 |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
259 |
ui.progress(_('crosschecking'), count, total=total) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
260 |
if f not in filenodes: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
261 |
lr = filelinkrevs[f][0] |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
262 |
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
|
263 |
|
27645
df8973e1fb45
verify: move file cross checking to its own function
Durham Goode <durham@fb.com>
parents:
27644
diff
changeset
|
264 |
if self.havecl: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
265 |
for f in sorted(filenodes): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
266 |
count += 1 |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
267 |
ui.progress(_('crosschecking'), count, total=total) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
268 |
if f not in filelinkrevs: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
269 |
try: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
270 |
fl = repo.file(f) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
271 |
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
|
272 |
except Exception: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
273 |
lr = None |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
274 |
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
|
275 |
|
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
276 |
ui.progress(_('crosschecking'), None) |
8291
f5c1a9094e41
verify: avoid exception on missing file revlog
Henrik Stuart <hg@hstuart.dk>
parents:
8225
diff
changeset
|
277 |
|
27644
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
278 |
def _verifyfiles(self, filenodes, filelinkrevs): |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
279 |
repo = self.repo |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
280 |
ui = self.ui |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
281 |
lrugetctx = self.lrugetctx |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
282 |
revlogv1 = self.revlogv1 |
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
283 |
havemf = self.havemf |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
284 |
ui.status(_("checking files\n")) |
8291
f5c1a9094e41
verify: avoid exception on missing file revlog
Henrik Stuart <hg@hstuart.dk>
parents:
8225
diff
changeset
|
285 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
286 |
storefiles = set() |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
287 |
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
|
288 |
if not f: |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
289 |
self.err(None, _("cannot decode filename '%s'") % f2) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
290 |
elif size > 0 or not revlogv1: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
291 |
storefiles.add(_normpath(f)) |
6892
dab95717058d
verify: check repo.store
Adrian Buehlmann <adrian@cadifra.com>
parents:
6889
diff
changeset
|
292 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
293 |
files = sorted(set(filenodes) | set(filelinkrevs)) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
294 |
total = len(files) |
27644
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
295 |
revisions = 0 |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
296 |
for i, f in enumerate(files): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
297 |
ui.progress(_('checking'), i, item=f, total=total) |
6892
dab95717058d
verify: check repo.store
Adrian Buehlmann <adrian@cadifra.com>
parents:
6889
diff
changeset
|
298 |
try: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
299 |
linkrevs = filelinkrevs[f] |
6892
dab95717058d
verify: check repo.store
Adrian Buehlmann <adrian@cadifra.com>
parents:
6889
diff
changeset
|
300 |
except KeyError: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
301 |
# in manifest but not in changelog |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
302 |
linkrevs = [] |
2778 | 303 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
304 |
if linkrevs: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
305 |
lr = linkrevs[0] |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
306 |
else: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
307 |
lr = None |
2778 | 308 |
|
3744
d626fc9e3985
verify: add rename link checking
Matt Mackall <mpm@selenic.com>
parents:
3473
diff
changeset
|
309 |
try: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
310 |
fl = repo.file(f) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
311 |
except error.RevlogError as e: |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
312 |
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
|
313 |
continue |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
314 |
|
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
315 |
for ff in fl.files(): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
316 |
try: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
317 |
storefiles.remove(ff) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
318 |
except KeyError: |
27446
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
319 |
self.warn(_(" warning: revlog '%s' not in fncache!") % ff) |
27445
cc178057ab49
verify: move fncachewarned up to a class variable
Durham Goode <durham@fb.com>
parents:
27444
diff
changeset
|
320 |
self.fncachewarned = True |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
321 |
|
27642
f6457349985b
verify: move checklog() onto class
Durham Goode <durham@fb.com>
parents:
27453
diff
changeset
|
322 |
self.checklog(fl, f, lr) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
323 |
seen = {} |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
324 |
rp = None |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
325 |
for i in fl: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
326 |
revisions += 1 |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
327 |
n = fl.node(i) |
27643
62ce86fcfd06
verify: move checkentry() to be a class function
Durham Goode <durham@fb.com>
parents:
27642
diff
changeset
|
328 |
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
|
329 |
if f in filenodes: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
330 |
if havemf and n not in filenodes[f]: |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
331 |
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
|
332 |
else: |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
333 |
del filenodes[f][n] |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
334 |
|
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
335 |
# verify contents |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
336 |
try: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
337 |
l = len(fl.read(n)) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
338 |
rp = fl.renamed(n) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
339 |
if l != fl.size(i): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
340 |
if len(fl.revision(n)) != fl.size(i): |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
341 |
self.err(lr, _("unpacked size is %s, %s expected") % |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
342 |
(l, fl.size(i)), f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
343 |
except error.CensoredNodeError: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
344 |
# experimental config: censor.policy |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
345 |
if ui.config("censor", "policy", "abort") == "abort": |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
346 |
self.err(lr, _("censored file data"), f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
347 |
except Exception as inst: |
27448
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
348 |
self.exc(lr, _("unpacking %s") % short(n), inst, f) |
3744
d626fc9e3985
verify: add rename link checking
Matt Mackall <mpm@selenic.com>
parents:
3473
diff
changeset
|
349 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
350 |
# check renames |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
351 |
try: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
352 |
if rp: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
353 |
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
|
354 |
ctx = lrugetctx(lr) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
355 |
found = False |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
356 |
for pctx in ctx.parents(): |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
357 |
if rp[0] in pctx: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
358 |
found = True |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
359 |
break |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
360 |
if not found: |
27446
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
361 |
self.warn(_("warning: copy source of '%s' not" |
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
362 |
" in parents of %s") % (f, ctx)) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
363 |
fl2 = repo.file(rp[0]) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
364 |
if not len(fl2): |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
365 |
self.err(lr, _("empty or missing copy source " |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
366 |
"revlog %s:%s") % (rp[0], short(rp[1])), f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
367 |
elif rp[1] == nullid: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
368 |
ui.note(_("warning: %s@%s: copy source" |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
369 |
" revision is nullid %s:%s\n") |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
370 |
% (f, lr, rp[0], short(rp[1]))) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
371 |
else: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
372 |
fl2.rev(rp[1]) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
373 |
except Exception as inst: |
27448
f4f2179077cb
verify: move exc() function onto class
Durham Goode <durham@fb.com>
parents:
27447
diff
changeset
|
374 |
self.exc(lr, _("checking rename of %s") % short(n), inst, f) |
6892
dab95717058d
verify: check repo.store
Adrian Buehlmann <adrian@cadifra.com>
parents:
6889
diff
changeset
|
375 |
|
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
376 |
# cross-check |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
377 |
if f in filenodes: |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
378 |
fns = [(lr, n) for n, lr in filenodes[f].iteritems()] |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
379 |
for lr, node in sorted(fns): |
27447
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
380 |
self.err(lr, _("%s in manifests not found") % short(node), |
d1b91c10ce70
verify: move err() to be a class function
Durham Goode <durham@fb.com>
parents:
27446
diff
changeset
|
381 |
f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
382 |
ui.progress(_('checking'), None) |
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
383 |
|
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
384 |
for f in storefiles: |
27446
6b2c1a1871a6
verify: move warn() to a class level function
Durham Goode <durham@fb.com>
parents:
27445
diff
changeset
|
385 |
self.warn(_("warning: orphan revlog '%s'") % f) |
27443
937e73a6e4ff
verify: move verify logic into a class
Durham Goode <durham@fb.com>
parents:
26900
diff
changeset
|
386 |
|
27644
331e5c28f5f0
verify: move filelog verification to its own function
Durham Goode <durham@fb.com>
parents:
27643
diff
changeset
|
387 |
return len(files), revisions |