Patchwork dispatch: only do __import__(debugger) when a debugger is requested

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date March 25, 2014, 3:46 p.m.
Message ID <397c258e34f9d7690bf2.1395762376@Iris>
Download mbox | patch
Permalink /patch/4062/
State Accepted
Commit dd2e25e49862213c73b5ea3412aa1fa5d8c92bab
Headers show

Comments

Jordi Gutiérrez Hermoso - March 25, 2014, 3:46 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1394219212 18000
#      Fri Mar 07 14:06:52 2014 -0500
# Node ID 397c258e34f9d7690bf2a23fbc2ac7515874deea
# Parent  3d1d16b19e7dd5e96e242daed86512429bc1d3f6
dispatch: only do __import__(debugger) when a debugger is requested

When having ui.debugger=somedebugger in one's ~/.hgrc, this then
somedebugger would be imported for every hg command. With this patch,
this import only happens if the --debugger parameter is passed.
Matt Mackall - March 25, 2014, 5:14 p.m.
On Tue, 2014-03-25 at 11:46 -0400, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1394219212 18000
> #      Fri Mar 07 14:06:52 2014 -0500
> # Node ID 397c258e34f9d7690bf2a23fbc2ac7515874deea
> # Parent  3d1d16b19e7dd5e96e242daed86512429bc1d3f6
> dispatch: only do __import__(debugger) when a debugger is requested

Queued for stable, thanks.

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -108,13 +108,17 @@ 
 
             # if we are in HGPLAIN mode, then disable custom debugging
             debugger = ui.config("ui", "debugger")
+            debugmod = pdb
             if not debugger or ui.plain():
                 debugger = 'pdb'
-
-            try:
-                debugmod = __import__(debugger)
-            except ImportError:
-                debugmod = pdb
+            elif '--debugger' in req.args:
+                # This import can be slow for fancy debuggers, so only
+                # do it when absolutely necessary, i.e. when actual
+                # debugging has been requested
+                try:
+                    debugmod = __import__(debugger)
+                except ImportError:
+                    pass # Leave debugmod = pdb
 
             debugtrace[debugger] = debugmod.set_trace
             debugmortem[debugger] = debugmod.post_mortem