mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 00:14:35 +03:00
19cda85a3a
Summary: It's pretty handy. The implementation is simple and clean. So move it from contrib and enable it by default. "import"s are adjusted to make the module checker happy. Security and UX wise, since we have `--debugger` already, adding another REPL seems fine. Test Plan: Ran all tests Reviewers: phillco, #mercurial Reviewed By: phillco Differential Revision: https://phabricator.intern.facebook.com/D6741283 Signature: 6741283:1516225662:ddc19a663e7ecef2a1fdaa5041f308dc838a8471
60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
# debugshell extension
|
|
"""a python shell with repo, changelog & manifest objects"""
|
|
|
|
from __future__ import absolute_import
|
|
import code
|
|
import sys
|
|
import mercurial
|
|
from mercurial import (
|
|
demandimport,
|
|
registrar,
|
|
)
|
|
|
|
cmdtable = {}
|
|
command = registrar.command(cmdtable)
|
|
|
|
def pdb(ui, repo, msg, **opts):
|
|
objects = {
|
|
'mercurial': mercurial,
|
|
'repo': repo,
|
|
'cl': repo.changelog,
|
|
'mf': repo.manifestlog,
|
|
}
|
|
|
|
code.interact(msg, local=objects)
|
|
|
|
def ipdb(ui, repo, msg, **opts):
|
|
import IPython
|
|
|
|
cl = repo.changelog
|
|
mf = repo.manifestlog
|
|
cl, mf # use variables to appease pyflakes
|
|
|
|
IPython.embed()
|
|
|
|
@command('debugshell|dbsh', [])
|
|
def debugshell(ui, repo, **opts):
|
|
bannermsg = "loaded repo : %s\n" \
|
|
"using source: %s" % (repo.root,
|
|
mercurial.__path__[0])
|
|
|
|
pdbmap = {
|
|
'pdb' : 'code',
|
|
'ipdb' : 'IPython'
|
|
}
|
|
|
|
debugger = ui.config("ui", "debugger")
|
|
if not debugger:
|
|
debugger = 'pdb'
|
|
|
|
# if IPython doesn't exist, fallback to code.interact
|
|
try:
|
|
with demandimport.deactivated():
|
|
__import__(pdbmap[debugger])
|
|
except ImportError:
|
|
ui.warn(("%s debugger specified but %s module was not found\n")
|
|
% (debugger, pdbmap[debugger]))
|
|
debugger = 'pdb'
|
|
|
|
getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts)
|