# HG changeset patch # User Joerg Sonnenberger # Date 2021-01-25 23:19:36 # Node ID f25c770c217b2a1b35c66bc5e68aac968af2a275 # Parent cfb6c10c08c218e80ff43a3f935cd1e44cfb451a 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 diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -3717,6 +3717,23 @@ def debugsub(ui, repo, rev=None): 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'))], diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -130,6 +130,7 @@ Show debug commands if there are no othe debugrevspec debugserve debugsetparents + debugshell debugsidedata debugssl debugstrip @@ -319,6 +320,7 @@ Show all commands + options 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 diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -1069,6 +1069,7 @@ Test list of internal help commands 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