mercurial/admin_commands.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 05 Apr 2024 14:11:02 +0200
changeset 51583 22cc679a7312
parent 51503 d4095f7b000a
child 51615 a93e60ebea09
permissions -rw-r--r--
phases: move RemotePhasesSummary to revision number This continue our quest to align more logic on revision number instead of node-ids. The motivation is similar to the change to `new_heads` and `analyze_remote_phases` a few changeset earlier. Again, we take this as an opportunity to rename the class, and the attribute to the new naming scheme. This will highlight the need for code update for any code using it an expecting node-ids. Many of the rev-num → node-id conversion we had to introduce in the previous changesets can now be removed. More will be removed in the future as we continue to align code toward rev-num usage. time saved in the 100 milliseconds order of magnitude for the mozilla-try benchmark I have been using.

# admin_commands.py - command processing for admin* commands
#
# Copyright 2022 Mercurial Developers
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

from .i18n import _
from .admin import chainsaw, verify
from . import error, registrar, transaction


table = {}
table.update(chainsaw.command._table)
command = registrar.command(table)


@command(
    b'admin::verify',
    [
        (b'c', b'check', [], _(b'add a check'), _(b'CHECK')),
        (b'o', b'option', [], _(b'pass an option to a check'), _(b'OPTION')),
    ],
    helpcategory=command.CATEGORY_MAINTENANCE,
)
def admin_verify(ui, repo, **opts):
    """verify the integrity of the repository

    Alternative UI to `hg verify` with a lot more control over the
    verification process and better error reporting.
    """

    if not repo.url().startswith(b'file:'):
        raise error.Abort(_(b"cannot verify bundle or remote repos"))

    if transaction.has_abandoned_transaction(repo):
        ui.warn(_(b"abandoned transaction found - run hg recover\n"))

    checks = opts.get("check", [])
    options = opts.get("option", [])

    funcs = verify.get_checks(repo, ui, names=checks, options=options)

    ui.status(_(b"running %d checks\n") % len(funcs))
    # Done in two times so the execution is separated from the resolving step
    for name, func in sorted(funcs.items(), key=lambda x: x[0]):
        ui.status(_(b"running %s\n") % name)
        errors = func()
        if errors:
            ui.warn(_(b"found %d errors\n") % len(errors))