Show More
@@ -1,59 +1,62 | |||||
1 | # debugshell extension |
|
1 | # debugshell extension | |
2 | """a python shell with repo, changelog & manifest objects""" |
|
2 | """a python shell with repo, changelog & manifest objects""" | |
3 |
|
3 | |||
4 | from __future__ import absolute_import |
|
4 | from __future__ import absolute_import | |
5 | import code |
|
5 | import code | |
6 | import mercurial |
|
6 | import mercurial | |
7 | import sys |
|
7 | import sys | |
8 | from mercurial import ( |
|
8 | from mercurial import ( | |
9 | demandimport, |
|
9 | demandimport, | |
|
10 | pycompat, | |||
10 | registrar, |
|
11 | registrar, | |
11 | ) |
|
12 | ) | |
12 |
|
13 | |||
13 | cmdtable = {} |
|
14 | cmdtable = {} | |
14 | command = registrar.command(cmdtable) |
|
15 | command = registrar.command(cmdtable) | |
15 |
|
16 | |||
16 | def pdb(ui, repo, msg, **opts): |
|
17 | def pdb(ui, repo, msg, **opts): | |
17 | objects = { |
|
18 | objects = { | |
18 | 'mercurial': mercurial, |
|
19 | 'mercurial': mercurial, | |
19 | 'repo': repo, |
|
20 | 'repo': repo, | |
20 | 'cl': repo.changelog, |
|
21 | 'cl': repo.changelog, | |
21 | 'mf': repo.manifestlog, |
|
22 | 'mf': repo.manifestlog, | |
22 | } |
|
23 | } | |
23 |
|
24 | |||
24 | code.interact(msg, local=objects) |
|
25 | code.interact(msg, local=objects) | |
25 |
|
26 | |||
26 | def ipdb(ui, repo, msg, **opts): |
|
27 | def ipdb(ui, repo, msg, **opts): | |
27 | import IPython |
|
28 | import IPython | |
28 |
|
29 | |||
29 | cl = repo.changelog |
|
30 | cl = repo.changelog | |
30 | mf = repo.manifestlog |
|
31 | mf = repo.manifestlog | |
31 | cl, mf # use variables to appease pyflakes |
|
32 | cl, mf # use variables to appease pyflakes | |
32 |
|
33 | |||
33 | IPython.embed() |
|
34 | IPython.embed() | |
34 |
|
35 | |||
35 | @command('debugshell|dbsh', []) |
|
36 | @command(b'debugshell|dbsh', []) | |
36 | def debugshell(ui, repo, **opts): |
|
37 | def debugshell(ui, repo, **opts): | |
37 | bannermsg = ("loaded repo : %s\n" |
|
38 | bannermsg = ("loaded repo : %s\n" | |
38 | "using source: %s" % (repo.root, |
|
39 | "using source: %s" % (pycompat.sysstr(repo.root), | |
39 | mercurial.__path__[0])) |
|
40 | mercurial.__path__[0])) | |
40 |
|
41 | |||
41 | pdbmap = { |
|
42 | pdbmap = { | |
42 | 'pdb' : 'code', |
|
43 | 'pdb' : 'code', | |
43 | 'ipdb' : 'IPython' |
|
44 | 'ipdb' : 'IPython' | |
44 | } |
|
45 | } | |
45 |
|
46 | |||
46 | debugger = ui.config("ui", "debugger") |
|
47 | debugger = ui.config(b"ui", b"debugger") | |
47 | if not debugger: |
|
48 | if not debugger: | |
48 | debugger = 'pdb' |
|
49 | debugger = 'pdb' | |
|
50 | else: | |||
|
51 | debugger = pycompat.sysstr(debugger) | |||
49 |
|
52 | |||
50 | # if IPython doesn't exist, fallback to code.interact |
|
53 | # if IPython doesn't exist, fallback to code.interact | |
51 | try: |
|
54 | try: | |
52 | with demandimport.deactivated(): |
|
55 | with demandimport.deactivated(): | |
53 | __import__(pdbmap[debugger]) |
|
56 | __import__(pdbmap[debugger]) | |
54 | except ImportError: |
|
57 | except ImportError: | |
55 | ui.warn(("%s debugger specified but %s module was not found\n") |
|
58 | ui.warn((b"%s debugger specified but %s module was not found\n") | |
56 | % (debugger, pdbmap[debugger])) |
|
59 | % (debugger, pdbmap[debugger])) | |
57 | debugger = 'pdb' |
|
60 | debugger = b'pdb' | |
58 |
|
61 | |||
59 | getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) |
|
62 | getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) |
General Comments 0
You need to be logged in to leave comments.
Login now