comparison mercurial/admin_commands.py @ 50986:752c5a5b73c6

admin-command: add verify command Start using the 'admin' namespace by adding a 'verify' command. Invocation is 'admin::verify'. The idea is to progressively add more focused checks than the existing verify command. To do so we need an advanced way to express what we want to check. The first check for admin::verify is 'working-copy.dirstate' which has no options, because it was an easy first check to implement, which verifies the integrity of the dirstate. This changeset was created with the help of Franck Bret.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 25 Jan 2023 15:34:27 +0100
parents 727428c7e1fc
children d4095f7b000a
comparison
equal deleted inserted replaced
50985:cf47b83d8ad0 50986:752c5a5b73c6
3 # Copyright 2022 Mercurial Developers 3 # Copyright 2022 Mercurial Developers
4 # 4 #
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from . import registrar 8 from .i18n import _
9 from .admin import verify
10 from . import error, registrar, transaction
11
9 12
10 table = {} 13 table = {}
11 command = registrar.command(table) 14 command = registrar.command(table)
15
16
17 @command(
18 b'admin::verify',
19 [
20 (b'c', b'check', [], _(b'add a check'), _(b'CHECK')),
21 (b'o', b'option', [], _(b'pass an option to a check'), _(b'OPTION')),
22 ],
23 helpcategory=command.CATEGORY_MAINTENANCE,
24 )
25 def admin_verify(ui, repo, **opts):
26 """verify the integrity of the repository
27
28 Alternative UI to `hg verify` with a lot more control over the
29 verification process and better error reporting.
30 """
31
32 if not repo.url().startswith(b'file:'):
33 raise error.Abort(_(b"cannot verify bundle or remote repos"))
34
35 if transaction.has_abandoned_transaction(repo):
36 ui.warn(_(b"abandoned transaction found - run hg recover\n"))
37
38 checks = opts.get("check", [])
39 options = opts.get("option", [])
40
41 funcs = verify.get_checks(repo, ui, names=checks, options=options)
42
43 ui.status(_(b"running %d checks\n") % len(funcs))
44 # Done in two times so the execution is separated from the resolving step
45 for name, func in sorted(funcs.items(), key=lambda x: x[0]):
46 ui.status(_(b"running %s\n") % name)
47 errors = func()
48 if errors:
49 ui.warn(_(b"found %d errors\n") % len(errors))