diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/debugcommands.py	Wed Aug 17 21:07:38 2016 -0700
@@ -0,0 +1,42 @@
+# debugcommands.py - command processing for debug* commands
+#
+# Copyright 2005-2016 Matt Mackall <mpm@selenic.com>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+from __future__ import absolute_import
+
+import os
+
+from .i18n import _
+from . import (
+    cmdutil,
+    commands,
+    error,
+    revlog,
+    scmutil,
+)
+
+# We reuse the command table from commands because it is easier than
+# teaching dispatch about multiple tables.
+command = cmdutil.command(commands.table)
+
+@command('debugancestor', [], _('[INDEX] REV1 REV2'), optionalrepo=True)
+def debugancestor(ui, repo, *args):
+    """find the ancestor revision of two revisions in a given index"""
+    if len(args) == 3:
+        index, rev1, rev2 = args
+        r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index)
+        lookup = r.lookup
+    elif len(args) == 2:
+        if not repo:
+            raise error.Abort(_('there is no Mercurial repository here '
+                                '(.hg not found)'))
+        rev1, rev2 = args
+        r = repo.changelog
+        lookup = repo.lookup
+    else:
+        raise error.Abort(_('either two or three arguments required'))
+    a = r.ancestor(lookup(rev1), lookup(rev2))
+    ui.write('%d:%s\n' % (r.rev(a), hex(a)))