mercurial/debugcommands.py
author Gregory Szorc <gregory.szorc@gmail.com>
Wed, 17 Aug 2016 21:07:38 -0700
changeset 30401 869d660b8669
child 30402 945f8229b30d
permissions -rw-r--r--
debugcommands: introduce standalone module for debug commands commands.py is our largest .py file by nearly 2x. Debug commands live in a world of their own. So let's extract them to their own module. We start with "debugancestor." We currently reuse the commands table with commands.py and have a hack in dispatch.py for loading debugcommands.py. In the future, we could potentially use a separate commands table and avoid the import of debugcommands.py.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
# debugcommands.py - command processing for debug* commands
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# Copyright 2005-2016 Matt Mackall <mpm@selenic.com>
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
#
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
from __future__ import absolute_import
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
import os
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
from .i18n import _
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
from . import (
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
    cmdutil,
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    15
    commands,
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    16
    error,
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    17
    revlog,
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    18
    scmutil,
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    19
)
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    20
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    21
# We reuse the command table from commands because it is easier than
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
# teaching dispatch about multiple tables.
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    23
command = cmdutil.command(commands.table)
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    24
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
@command('debugancestor', [], _('[INDEX] REV1 REV2'), optionalrepo=True)
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
def debugancestor(ui, repo, *args):
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    27
    """find the ancestor revision of two revisions in a given index"""
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    28
    if len(args) == 3:
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    29
        index, rev1, rev2 = args
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    30
        r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index)
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
        lookup = r.lookup
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
    elif len(args) == 2:
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
        if not repo:
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
            raise error.Abort(_('there is no Mercurial repository here '
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
                                '(.hg not found)'))
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    36
        rev1, rev2 = args
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    37
        r = repo.changelog
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
        lookup = repo.lookup
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
    else:
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    40
        raise error.Abort(_('either two or three arguments required'))
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    41
    a = r.ancestor(lookup(rev1), lookup(rev2))
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    42
    ui.write('%d:%s\n' % (r.rev(a), hex(a)))