12 ) |
12 ) |
13 |
13 |
14 cmdtable = {} |
14 cmdtable = {} |
15 command = registrar.command(cmdtable) |
15 command = registrar.command(cmdtable) |
16 |
16 |
|
17 |
17 def pdb(ui, repo, msg, **opts): |
18 def pdb(ui, repo, msg, **opts): |
18 objects = { |
19 objects = { |
19 'mercurial': mercurial, |
20 'mercurial': mercurial, |
20 'repo': repo, |
21 'repo': repo, |
21 'cl': repo.changelog, |
22 'cl': repo.changelog, |
22 'mf': repo.manifestlog, |
23 'mf': repo.manifestlog, |
23 } |
24 } |
24 |
25 |
25 code.interact(msg, local=objects) |
26 code.interact(msg, local=objects) |
26 |
27 |
|
28 |
27 def ipdb(ui, repo, msg, **opts): |
29 def ipdb(ui, repo, msg, **opts): |
28 import IPython |
30 import IPython |
29 |
31 |
30 cl = repo.changelog |
32 cl = repo.changelog |
31 mf = repo.manifestlog |
33 mf = repo.manifestlog |
32 cl, mf # use variables to appease pyflakes |
34 cl, mf # use variables to appease pyflakes |
33 |
35 |
34 IPython.embed() |
36 IPython.embed() |
35 |
37 |
|
38 |
36 @command(b'debugshell|dbsh', []) |
39 @command(b'debugshell|dbsh', []) |
37 def debugshell(ui, repo, **opts): |
40 def debugshell(ui, repo, **opts): |
38 bannermsg = ("loaded repo : %s\n" |
41 bannermsg = "loaded repo : %s\n" "using source: %s" % ( |
39 "using source: %s" % (pycompat.sysstr(repo.root), |
42 pycompat.sysstr(repo.root), |
40 mercurial.__path__[0])) |
43 mercurial.__path__[0], |
|
44 ) |
41 |
45 |
42 pdbmap = { |
46 pdbmap = {'pdb': 'code', 'ipdb': 'IPython'} |
43 'pdb' : 'code', |
|
44 'ipdb' : 'IPython' |
|
45 } |
|
46 |
47 |
47 debugger = ui.config(b"ui", b"debugger") |
48 debugger = ui.config(b"ui", b"debugger") |
48 if not debugger: |
49 if not debugger: |
49 debugger = 'pdb' |
50 debugger = 'pdb' |
50 else: |
51 else: |
53 # if IPython doesn't exist, fallback to code.interact |
54 # if IPython doesn't exist, fallback to code.interact |
54 try: |
55 try: |
55 with demandimport.deactivated(): |
56 with demandimport.deactivated(): |
56 __import__(pdbmap[debugger]) |
57 __import__(pdbmap[debugger]) |
57 except ImportError: |
58 except ImportError: |
58 ui.warn((b"%s debugger specified but %s module was not found\n") |
59 ui.warn( |
59 % (debugger, pdbmap[debugger])) |
60 b"%s debugger specified but %s module was not found\n" |
|
61 % (debugger, pdbmap[debugger]) |
|
62 ) |
60 debugger = b'pdb' |
63 debugger = b'pdb' |
61 |
64 |
62 getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) |
65 getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) |