Mercurial > hg
comparison mercurial/debugcommands.py @ 30401:869d660b8669
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 17 Aug 2016 21:07:38 -0700 |
parents | |
children | 945f8229b30d |
comparison
equal
deleted
inserted
replaced
30400:d1a0a64f6e16 | 30401:869d660b8669 |
---|---|
1 # debugcommands.py - command processing for debug* commands | |
2 # | |
3 # Copyright 2005-2016 Matt Mackall <mpm@selenic.com> | |
4 # | |
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. | |
7 | |
8 from __future__ import absolute_import | |
9 | |
10 import os | |
11 | |
12 from .i18n import _ | |
13 from . import ( | |
14 cmdutil, | |
15 commands, | |
16 error, | |
17 revlog, | |
18 scmutil, | |
19 ) | |
20 | |
21 # We reuse the command table from commands because it is easier than | |
22 # teaching dispatch about multiple tables. | |
23 command = cmdutil.command(commands.table) | |
24 | |
25 @command('debugancestor', [], _('[INDEX] REV1 REV2'), optionalrepo=True) | |
26 def debugancestor(ui, repo, *args): | |
27 """find the ancestor revision of two revisions in a given index""" | |
28 if len(args) == 3: | |
29 index, rev1, rev2 = args | |
30 r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index) | |
31 lookup = r.lookup | |
32 elif len(args) == 2: | |
33 if not repo: | |
34 raise error.Abort(_('there is no Mercurial repository here ' | |
35 '(.hg not found)')) | |
36 rev1, rev2 = args | |
37 r = repo.changelog | |
38 lookup = repo.lookup | |
39 else: | |
40 raise error.Abort(_('either two or three arguments required')) | |
41 a = r.ancestor(lookup(rev1), lookup(rev2)) | |
42 ui.write('%d:%s\n' % (r.rev(a), hex(a))) |