Mercurial > hg
annotate mercurial/admin/verify.py @ 51461:47752632b4fc
branchcache: rename `load` to `_load_heads`
We are about to have more similar function, we rename the existing one to a more
meaningful name and mark it private in the process.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 26 Feb 2024 15:12:20 +0100 |
parents | 752c5a5b73c6 |
children | dcb00d5c397a |
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 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 import collections |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 import copy |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 import functools |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 from ..i18n import _ |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 from .. import error, pycompat, registrar, requirements |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 from ..utils import stringutil |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
15 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 verify_table = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 verify_alias_table = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 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
|
20 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 # 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
|
23 # 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
|
24 # For an example, see the `revlogs` check. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 def noop_func(*args, **kwargs): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 return |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 @check(b"working-copy.dirstate", alias=b"dirstate") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 def check_dirstate(ui, repo, **options): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 ui.status(_(b"checking dirstate\n")) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 parent1, parent2 = repo.dirstate.parents() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 m1 = repo[parent1].manifest() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 m2 = repo[parent2].manifest() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 errors = 0 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 is_narrow = requirements.NARROW_REQUIREMENT in repo.requirements |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 narrow_matcher = repo.narrowmatch() if is_narrow else None |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 for err in repo.dirstate.verify(m1, m2, narrow_matcher): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 ui.warn(err[0] % err[1:]) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 errors += 1 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 return errors |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
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 # Tree of all checks and their associated function |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 pyramid = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
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 def build_pyramid(table, full_pyramid): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 """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
|
54 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
|
55 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
|
56 cursor = full_pyramid |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 levels = entry.split(b".") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 for level in levels[:-1]: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 current_node = cursor.setdefault(level, {}) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 cursor = current_node |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 if cursor.get(levels[-1]) is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 cursor[levels[-1]] = (entry, func) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 elif func is not noop_func: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
64 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
|
65 raise error.ProgrammingError(m) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 |
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 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
|
69 """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
|
70 (qualified_check_name, check_function) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 # Examples |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
74 Using a full qualified name: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 "working-copy.dirstate" -> { |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
76 "working-copy.dirstate": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 } |
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 Using a *prefix* of a qualified name: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
80 "store.revlogs" -> { |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 "store.revlogs.changelog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 "store.revlogs.manifestlog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
83 "store.revlogs.filelog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 } |
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 Using a defined alias: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
87 "revlogs" -> { |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 "store.revlogs.changelog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 "store.revlogs.manifestlog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 "store.revlogs.filelog": CF, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 } |
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 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
|
94 """ |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
95 if table is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 table = verify_table |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 if alias_table is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 alias_table = verify_alias_table |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 if name == b"full": |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 return table |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 checks = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
104 # is it a full name? |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 check = table.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
107 if check is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
108 # is it an alias? |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 qualified_name = alias_table.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 if qualified_name is not None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
111 name = qualified_name |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 check = table.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 split = name.split(b".", 1) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 if len(split) == 2: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 # split[0] can be an alias |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 qualified_name = alias_table.get(split[0]) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 if qualified_name is not None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 name = b"%s.%s" % (qualified_name, split[1]) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 check = table.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 qualified_name = name |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 # 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
|
125 # have an explicit alias. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 levels = name.split(b".") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 if full_pyramid is not None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
128 if not full_pyramid: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
129 build_pyramid(table, full_pyramid) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 pyramid.clear() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 pyramid.update(full_pyramid.items()) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
133 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
134 build_pyramid(table, pyramid) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
135 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
136 subtree = pyramid |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 # Find subtree |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
138 for level in levels: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 subtree = subtree.get(level) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 if subtree is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 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
|
142 hint = error.similarity_hint(hint) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
143 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
144 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
|
145 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
146 # Get all checks in that subtree |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
147 if isinstance(subtree, dict): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
148 stack = list(subtree.items()) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
149 while stack: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
150 current_name, entry = stack.pop() |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
151 if isinstance(entry, dict): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
152 stack.extend(entry.items()) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
153 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
154 # (qualified_name, func) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
155 checks[entry[0]] = entry[1] |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
156 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
157 checks[name] = check |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
158 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
159 return checks |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
160 |
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 def pass_options( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
163 ui, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
164 checks, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
165 options, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
166 table=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
167 alias_table=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
168 full_pyramid=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
169 ): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
170 """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
|
171 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
|
172 function.""" |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
173 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
|
174 to_modify = collections.defaultdict(dict) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
175 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
176 if not checks: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
177 raise error.Error(_(b"`checks` required")) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
178 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
179 for option in sorted(options): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
180 split = option.split(b":") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
181 hint = _( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
182 b"syntax is 'check:option=value', " |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 b"eg. revlogs.changelog:copies=yes" |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
184 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
185 option_error = error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
186 _(b"invalid option '%s'") % option, hint=hint |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
187 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
188 if len(split) != 2: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
189 raise option_error |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
190 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
191 check_name, option_value = split |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
192 if not option_value: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
193 raise option_error |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
194 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
195 split = option_value.split(b"=") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
196 if len(split) != 2: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
197 raise option_error |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
198 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
199 option_name, value = split |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
200 if not value: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
201 raise option_error |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
202 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
203 path = b"%s:%s" % (check_name, option_name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
204 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
205 matching_checks = find_checks( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
206 check_name, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
207 table=table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
208 alias_table=alias_table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
209 full_pyramid=full_pyramid, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
210 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
211 for name in matching_checks: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
212 check = checks.get(name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
213 if check is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
214 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
|
215 raise error.InputError(msg % (name, option_name)) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
216 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
217 assert hasattr(check, "func") # help Pytype |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
218 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
219 if not hasattr(check.func, "options"): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
220 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
221 _(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
|
222 ) |
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 try: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
225 matching_option = next( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 (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
|
227 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
228 except StopIteration: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
230 _(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
|
231 ) |
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 # 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
|
234 _name, typ, _docstring = matching_option |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
235 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
236 as_typed = None |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 if isinstance(typ, bool): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 as_bool = stringutil.parsebool(value) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
239 if as_bool is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
240 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
241 _(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
|
242 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 as_typed = as_bool |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
244 elif isinstance(typ, list): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
245 as_list = stringutil.parselist(value) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
246 if as_list is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
247 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
248 _(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
|
249 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
250 as_typed = as_list |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
251 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
252 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
|
253 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
254 if option_name in to_modify[name]: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
255 raise error.InputError( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
256 _(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
|
257 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
258 else: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
259 assert as_typed is not None |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 to_modify[name][option_name] = as_typed |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
261 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
262 # 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
|
263 # 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
|
264 for name, f in checks.items(): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
265 if name not in to_modify: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
266 to_modify[name] = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
267 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
268 # Merge default options with command line options |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
269 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
|
270 check = checks.get(check_name) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 func = checks[check_name] |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
272 merged_options = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
273 # help Pytype |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
274 assert check is not None |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
275 assert check.func is not None |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
276 assert hasattr(check.func, "options") |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
277 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
278 if check.func.options: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
279 # 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
|
280 merged_options = { |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
281 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
|
282 } |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
283 if cmd_options: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
284 for k, v in cmd_options.items(): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 merged_options[k] = v |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
286 options = pycompat.strkwargs(merged_options) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
287 checks[check_name] = functools.partial(func, **options) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
288 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
|
289 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
290 return checks |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
291 |
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 def get_checks( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 repo, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 ui, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
296 names=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
297 options=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
298 table=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
299 alias_table=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
300 full_pyramid=None, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
301 ): |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
302 """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
|
303 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
|
304 values take precedence on default ones) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
305 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
306 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
|
307 functions with resolved options. |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
308 """ |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
309 funcs = {} |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
310 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
311 if names is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
312 names = [] |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
313 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
314 if options is None: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
315 options = [] |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
316 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 # find checks |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
318 for name in names: |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
319 matched = find_checks( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
320 name, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
321 table=table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 alias_table=alias_table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
323 full_pyramid=full_pyramid, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
324 ) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
325 matched_names = b", ".join(matched) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
326 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
|
327 funcs.update(matched) |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
328 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
329 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
|
330 |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
331 # resolve options |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
332 checks = pass_options( |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
333 ui, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
334 funcs, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
335 options, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
336 table=table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
337 alias_table=alias_table, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
338 full_pyramid=full_pyramid, |
752c5a5b73c6
admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 ) |
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 return checks |