debug: move extensions debug behind a dedicated flag
authorBoris Feld <boris.feld@octobus.net>
Mon, 16 Jul 2018 18:02:30 +0200
changeset 38727 fcb517ff9562
parent 38726 d79f3afb079e
child 38728 88be288e8ac1
debug: move extensions debug behind a dedicated flag Since b86664c81833, we process the `--debug` flag earlier. This is overall good and useful, but has at least one negative side effect. Previously the debug message we report when trying to import extensions were issued before we processed the `--debug` flag. Now they happen after. Before: $ ./hg id --debug 21f507b8de2f9c1606e9aeb5ec7d2a6dedb7a4a7 tip After: $ ./hg id --debug ☿ (revset-bench) could not import hgext.evolve (No module named evolve): trying hgext3rd.evolve could not import hgext.mercurial_keyring (No module named mercurial_keyring): trying hgext3rd.mercurial_keyring could not import hgext3rd.mercurial_keyring (No module named mercurial_keyring): trying mercurial_keyring could not import hgext.hggit (No module named hggit): trying hgext3rd.hggit could not import hgext3rd.hggit (No module named hggit): trying hggit 21f507b8de2f9c1606e9aeb5ec7d2a6dedb7a4a7 tip (This get worse if --traceback is used). To work around this, we move this extensions related debug message behind a new flag 'devel.debug.extensions' and restore the previous output. I'm not fully happy about using the 'devel' section for a flag that can be used by legitimate users to debug extensions issues. However, it fits well next to other `devel.devel.*` options and is mostly used by extensions author anyway. We might move it to another, more appropriate section in the future (using alias).
mercurial/configitems.py
mercurial/extensions.py
tests/test-bad-extension.t
--- a/mercurial/configitems.py	Mon Jul 16 11:38:56 2018 -0700
+++ b/mercurial/configitems.py	Mon Jul 16 18:02:30 2018 +0200
@@ -372,6 +372,9 @@
 coreconfigitem('devel', 'warn-config-unknown',
     default=None,
 )
+coreconfigitem('devel', 'debug.extensions',
+    default=False,
+)
 coreconfigitem('devel', 'debug.peer-request',
     default=False,
 )
--- a/mercurial/extensions.py	Mon Jul 16 11:38:56 2018 -0700
+++ b/mercurial/extensions.py	Mon Jul 16 18:02:30 2018 +0200
@@ -123,10 +123,11 @@
 def _reportimporterror(ui, err, failed, next):
     # note: this ui.debug happens before --debug is processed,
     #       Use --config ui.debug=1 to see them.
-    ui.debug('could not import %s (%s): trying %s\n'
-             % (failed, stringutil.forcebytestr(err), next))
-    if ui.debugflag:
-        ui.traceback()
+    if ui.configbool('devel', 'debug.extensions'):
+        ui.debug('could not import %s (%s): trying %s\n'
+                 % (failed, stringutil.forcebytestr(err), next))
+        if ui.debugflag:
+            ui.traceback()
 
 def _rejectunicode(name, xs):
     if isinstance(xs, (list, set, tuple)):
--- a/tests/test-bad-extension.t	Mon Jul 16 11:38:56 2018 -0700
+++ b/tests/test-bad-extension.t	Mon Jul 16 18:02:30 2018 +0200
@@ -72,10 +72,9 @@
   $ hg --config extensions.badexts=showbadexts.py showbadexts 2>&1 | grep '^BADEXTS'
   BADEXTS: badext badext2
 
-show traceback for ImportError of hgext.name if debug is set
-(note that --debug option isn't applied yet when loading extensions)
+show traceback for ImportError of hgext.name if devel.debug.extensions is set
 
-  $ (hg help help --traceback --config ui.debug=yes 2>&1) \
+  $ (hg help help --traceback --debug --config devel.debug.extensions=yes 2>&1) \
   > | grep -v '^ ' \
   > | egrep 'extension..[^p]|^Exception|Traceback|ImportError|not import'
   *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow