debugshell: add a simple command for starting an interactive shell
authorJoerg Sonnenberger <joerg@bec.de>
Tue, 26 Jan 2021 00:19:36 +0100
changeset 46392 f25c770c217b
parent 46391 cfb6c10c08c2
child 46393 66e8e279133b
debugshell: add a simple command for starting an interactive shell This simplifies interactive exploration of the Mercurial APIs. The ui and repo instances are provided as local variables. Differential Revision: https://phab.mercurial-scm.org/D9866
mercurial/debugcommands.py
tests/test-completion.t
tests/test-help.t
--- a/mercurial/debugcommands.py	Mon Jan 25 11:34:23 2021 +0100
+++ b/mercurial/debugcommands.py	Tue Jan 26 00:19:36 2021 +0100
@@ -3717,6 +3717,23 @@
         ui.writenoi18n(b' revision %s\n' % v[1])
 
 
+@command(b'debugshell', optionalrepo=True)
+def debugshell(ui, repo):
+    """run an interactive Python interpreter
+
+    The local namespace is provided with a reference to the ui and
+    the repo instance (if available).
+    """
+    import code
+
+    imported_objects = {
+        'ui': ui,
+        'repo': repo,
+    }
+
+    code.interact(local=imported_objects)
+
+
 @command(
     b'debugsuccessorssets',
     [(b'', b'closest', False, _(b'return closest successors sets only'))],
--- a/tests/test-completion.t	Mon Jan 25 11:34:23 2021 +0100
+++ b/tests/test-completion.t	Tue Jan 26 00:19:36 2021 +0100
@@ -130,6 +130,7 @@
   debugrevspec
   debugserve
   debugsetparents
+  debugshell
   debugsidedata
   debugssl
   debugstrip
@@ -319,6 +320,7 @@
   debugrevspec: optimize, show-revs, show-set, show-stage, no-optimized, verify-optimized
   debugserve: sshstdio, logiofd, logiofile
   debugsetparents: 
+  debugshell: 
   debugsidedata: changelog, manifest, dir
   debugssl: 
   debugstrip: rev, force, no-backup, nobackup, , keep, bookmark, soft
--- a/tests/test-help.t	Mon Jan 25 11:34:23 2021 +0100
+++ b/tests/test-help.t	Tue Jan 26 00:19:36 2021 +0100
@@ -1069,6 +1069,7 @@
    debugsetparents
                  manually set the parents of the current working directory
                  (DANGEROUS)
+   debugshell    run an interactive Python interpreter
    debugsidedata
                  dump the side data for a cl/manifest/file revision
    debugssl      test a secure connection to a server