[PATCH 2 of 2] dispatch: add ability to specify a custom pdb module as a debugger

Augie Fackler raf at durin42.com
Tue Jul 16 10:21:59 CDT 2013


On Sat, Jul 13, 2013 at 05:16:56PM -0500, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley at gmail.com>
> # Date 1373752000 18000
> #      Sat Jul 13 16:46:40 2013 -0500
> # Node ID 42113a6e12bc864e044bacb57407a68a97d7f1da
> # Parent  15a903bca551318cd0c3f42484374a8b8acd08e5
> dispatch: add ability to specify a custom pdb module as a debugger

+1 in principle, not willing to queue because dispatch makes my head
spin a little.

>
> This adds the ability to specify a config option, ui.debugger, to a custom pdb
> module, such as ipdb, and have mercurial use that as its debugger.
>
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -97,24 +97,49 @@
>                  # copy configs that were passed on the cmdline (--config) to
>                  # the repo ui
>                  for cfg in cfgs:
>                      req.repo.ui.setconfig(*cfg)
>
> +            debugger = ui.config("ui", "debugger")
> +            if not debugger:
> +                debugger = 'pdb'
> +
> +            try:
> +                ipdb = __import__(debugger)
> +            except ImportError:
> +                ipdb = pdb
> +
> +            debugtrace = {
> +                'pdb'    : pdb.set_trace,
> +                debugger : ipdb.set_trace,
> +            }
> +
> +            debugmortem = {
> +                'pdb'    : pdb.post_mortem,
> +                debugger : ipdb.post_mortem,
> +            }
> +
>              # enter the debugger before command execution
>              if '--debugger' in req.args:
>                  ui.warn(_("entering debugger - "
>                          "type c to continue starting hg or h for help\n"))
> -                pdb.set_trace()
> +
> +                if (debugger != 'pdb' and
> +                    debugtrace[debugger] == debugtrace['pdb']):
> +                    ui.warn(_("%s debugger specified "
> +                              "but its module was not found\n") % debugger)
> +
> +                debugtrace[debugger]()
>              try:
>                  return _dispatch(req)
>              finally:
>                  ui.flush()
>          except: # re-raises
>              # enter the debugger when we hit an exception
>              if '--debugger' in req.args:
>                  traceback.print_exc()
> -                pdb.post_mortem(sys.exc_info()[2])
> +                debugmortem[debugger](sys.exc_info()[2])
>              ui.traceback()
>              raise
>
>      # Global exception handling, alphabetically
>      # Mercurial-specific first, followed by built-in and library exceptions
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list