Mercurial > hg
annotate mercurial/admin/verify.py @ 52179:c90e0f65896e
rust-revlog: generalize an error message
This is used for more than the nodemap data.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 31 Jul 2024 15:11:27 +0200 |
parents | 1c5810ce737e |
children |
rev | line source |
---|---|
50989
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 # admin/verify.py - better repository integrity checking for Mercurial |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 # |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 # Copyright 2023 Octobus <contact@octobus.net> |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 # |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
51864
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51614
diff
changeset
|
8 from __future__ import annotations |
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51614
diff
changeset
|
9 |
50989
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 import collections |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 import copy |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 import functools |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 from ..i18n import _ |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
15 from .. import error, pycompat, registrar, requirements |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 from ..utils import stringutil |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 verify_table = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 verify_alias_table = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 check = registrar.verify_check(verify_table, verify_alias_table) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 # Use this to declare options/aliases in the middle of the hierarchy. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 # Checks like these are not run themselves and cannot have a body. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 # For an example, see the `revlogs` check. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 def noop_func(*args, **kwargs): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 return |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 @check(b"working-copy.dirstate", alias=b"dirstate") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 def check_dirstate(ui, repo, **options): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 ui.status(_(b"checking dirstate\n")) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 parent1, parent2 = repo.dirstate.parents() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 m1 = repo[parent1].manifest() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 m2 = repo[parent2].manifest() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 errors = 0 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 is_narrow = requirements.NARROW_REQUIREMENT in repo.requirements |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 narrow_matcher = repo.narrowmatch() if is_narrow else None |
51613
dcb00d5c397a
admin-verify: pass p1 down to the dirstate function
Raphaël Gomès <rgomes@octobus.net>
parents:
50989
diff
changeset
|
42 for err in repo.dirstate.verify(m1, m2, parent1, narrow_matcher): |
51614
2a27b921cd91
admin-verify: fix error message handling
Raphaël Gomès <rgomes@octobus.net>
parents:
51613
diff
changeset
|
43 ui.warn(err) |
50989
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 errors += 1 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 return errors |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 # Tree of all checks and their associated function |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 pyramid = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 def build_pyramid(table, full_pyramid): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 """Create a pyramid of checks of the registered checks. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 It is a name-based hierarchy that can be arbitrarily nested.""" |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 for entry, func in sorted(table.items(), key=lambda x: x[0], reverse=True): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 cursor = full_pyramid |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 levels = entry.split(b".") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 for level in levels[:-1]: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 current_node = cursor.setdefault(level, {}) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 cursor = current_node |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 if cursor.get(levels[-1]) is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 cursor[levels[-1]] = (entry, func) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
64 elif func is not noop_func: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 m = b"intermediate checks need to use `verify.noop_func`" |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 raise error.ProgrammingError(m) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
68 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
69 def find_checks(name, table=None, alias_table=None, full_pyramid=None): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
70 """Find all checks for a given name and returns a dict of |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 (qualified_check_name, check_function) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 # Examples |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
74 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 Using a full qualified name: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
76 "working-copy.dirstate" -> { |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 "working-copy.dirstate": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 } |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
80 Using a *prefix* of a qualified name: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 "store.revlogs" -> { |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 "store.revlogs.changelog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
83 "store.revlogs.manifestlog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 "store.revlogs.filelog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
85 } |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
86 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
87 Using a defined alias: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 "revlogs" -> { |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 "store.revlogs.changelog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 "store.revlogs.manifestlog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 "store.revlogs.filelog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
92 } |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
93 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
94 Using something that is none of the above will be an error. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
95 """ |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 if table is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 table = verify_table |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 if alias_table is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 alias_table = verify_alias_table |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 if name == b"full": |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 return table |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 checks = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
104 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 # is it a full name? |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 check = table.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
107 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
108 if check is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 # is it an alias? |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 qualified_name = alias_table.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
111 if qualified_name is not None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 name = qualified_name |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 check = table.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 split = name.split(b".", 1) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 if len(split) == 2: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 # split[0] can be an alias |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 qualified_name = alias_table.get(split[0]) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 if qualified_name is not None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 name = b"%s.%s" % (qualified_name, split[1]) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 check = table.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 qualified_name = name |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
125 # Maybe it's a subtree in the check hierarchy that does not |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 # have an explicit alias. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 levels = name.split(b".") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
128 if full_pyramid is not None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
129 if not full_pyramid: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 build_pyramid(table, full_pyramid) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 pyramid.clear() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
133 pyramid.update(full_pyramid.items()) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
134 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
135 build_pyramid(table, pyramid) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
136 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 subtree = pyramid |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
138 # Find subtree |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 for level in levels: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 subtree = subtree.get(level) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 if subtree is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
142 hint = error.getsimilar(list(alias_table) + list(table), name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
143 hint = error.similarity_hint(hint) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
144 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
145 raise error.InputError(_(b"unknown check %s" % name), hint=hint) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
146 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
147 # Get all checks in that subtree |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
148 if isinstance(subtree, dict): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
149 stack = list(subtree.items()) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
150 while stack: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
151 current_name, entry = stack.pop() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
152 if isinstance(entry, dict): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
153 stack.extend(entry.items()) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
154 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
155 # (qualified_name, func) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
156 checks[entry[0]] = entry[1] |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
157 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
158 checks[name] = check |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
159 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
160 return checks |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
161 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
162 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
163 def pass_options( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
164 ui, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
165 checks, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
166 options, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
167 table=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
168 alias_table=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
169 full_pyramid=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
170 ): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
171 """Given a dict of checks (fully qualified name to function), and a list |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
172 of options as given by the user, pass each option down to the right check |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
173 function.""" |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
174 ui.debug(b"passing options to check functions\n") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
175 to_modify = collections.defaultdict(dict) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
176 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
177 if not checks: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
178 raise error.Error(_(b"`checks` required")) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
179 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
180 for option in sorted(options): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
181 split = option.split(b":") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
182 hint = _( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 b"syntax is 'check:option=value', " |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
184 b"eg. revlogs.changelog:copies=yes" |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
185 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
186 option_error = error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
187 _(b"invalid option '%s'") % option, hint=hint |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
188 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
189 if len(split) != 2: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
190 raise option_error |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
191 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
192 check_name, option_value = split |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
193 if not option_value: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
194 raise option_error |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
195 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
196 split = option_value.split(b"=") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
197 if len(split) != 2: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
198 raise option_error |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
199 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
200 option_name, value = split |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
201 if not value: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
202 raise option_error |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
203 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
204 path = b"%s:%s" % (check_name, option_name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
205 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
206 matching_checks = find_checks( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
207 check_name, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
208 table=table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
209 alias_table=alias_table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
210 full_pyramid=full_pyramid, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
211 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
212 for name in matching_checks: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
213 check = checks.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
214 if check is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
215 msg = _(b"specified option '%s' for unselected check '%s'\n") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
216 raise error.InputError(msg % (name, option_name)) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
217 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
218 assert hasattr(check, "func") # help Pytype |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
219 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
220 if not hasattr(check.func, "options"): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
221 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
222 _(b"check '%s' has no option '%s'") % (name, option_name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
223 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
224 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
225 try: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 matching_option = next( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
227 (o for o in check.func.options if o[0] == option_name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
228 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 except StopIteration: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
230 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
231 _(b"check '%s' has no option '%s'") % (name, option_name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
232 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
233 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
234 # transform the argument from cli string to the expected Python type |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
235 _name, typ, _docstring = matching_option |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
236 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 as_typed = None |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 if isinstance(typ, bool): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
239 as_bool = stringutil.parsebool(value) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
240 if as_bool is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
241 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
242 _(b"'%s' is not a boolean ('%s')") % (path, value) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
244 as_typed = as_bool |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
245 elif isinstance(typ, list): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
246 as_list = stringutil.parselist(value) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
247 if as_list is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
248 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
249 _(b"'%s' is not a list ('%s')") % (path, value) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
250 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
251 as_typed = as_list |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
252 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
253 raise error.ProgrammingError(b"unsupported type %s", type(typ)) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
254 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
255 if option_name in to_modify[name]: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
256 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
257 _(b"duplicated option '%s' for '%s'") % (option_name, name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
258 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
259 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 assert as_typed is not None |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
261 to_modify[name][option_name] = as_typed |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
262 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
263 # Manage case where a check is set but without command line options |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
264 # it will later be set with default check options values |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
265 for name, f in checks.items(): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
266 if name not in to_modify: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
267 to_modify[name] = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
268 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
269 # Merge default options with command line options |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
270 for check_name, cmd_options in to_modify.items(): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 check = checks.get(check_name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
272 func = checks[check_name] |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
273 merged_options = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
274 # help Pytype |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
275 assert check is not None |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
276 assert check.func is not None |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
277 assert hasattr(check.func, "options") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
278 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
279 if check.func.options: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
280 # copy the default value in case it's mutable (list, etc.) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
281 merged_options = { |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
282 o[0]: copy.deepcopy(o[1]) for o in check.func.options |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
283 } |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
284 if cmd_options: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 for k, v in cmd_options.items(): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
286 merged_options[k] = v |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
287 options = pycompat.strkwargs(merged_options) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
288 checks[check_name] = functools.partial(func, **options) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
289 ui.debug(b"merged options for '%s': '%r'\n" % (check_name, options)) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
290 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
291 return checks |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
292 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
293 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 def get_checks( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 repo, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
296 ui, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
297 names=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
298 options=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
299 table=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
300 alias_table=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
301 full_pyramid=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
302 ): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
303 """Given a list of function names and optionally a list of |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
304 options, return matched checks with merged options (command line options |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
305 values take precedence on default ones) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
306 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
307 It runs find checks, then resolve options and returns a dict of matched |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
308 functions with resolved options. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
309 """ |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
310 funcs = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
311 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
312 if names is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
313 names = [] |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
314 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
315 if options is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
316 options = [] |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
318 # find checks |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
319 for name in names: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
320 matched = find_checks( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
321 name, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 table=table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
323 alias_table=alias_table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
324 full_pyramid=full_pyramid, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
325 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
326 matched_names = b", ".join(matched) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
327 ui.debug(b"found checks '%s' for name '%s'\n" % (matched_names, name)) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
328 funcs.update(matched) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
329 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
330 funcs = {n: functools.partial(f, ui, repo) for n, f in funcs.items()} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
331 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
332 # resolve options |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
333 checks = pass_options( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
334 ui, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
335 funcs, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
336 options, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
337 table=table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
338 alias_table=alias_table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 full_pyramid=full_pyramid, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
340 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
341 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
342 return checks |