debug: process --debug flag earlier
authorBoris Feld <boris.feld@octobus.net>
Tue, 19 Jun 2018 19:18:31 +0100
changeset 38535 b86664c81833
parent 38534 9ee202679a76
child 38536 8c38d2948217
debug: process --debug flag earlier This allow the verbosity level to be set correctly during extension initialization.
mercurial/dispatch.py
tests/test-extension.t
--- a/mercurial/dispatch.py	Tue Jun 19 19:10:31 2018 +0100
+++ b/mercurial/dispatch.py	Tue Jun 19 19:18:31 2018 +0100
@@ -811,6 +811,13 @@
     if req.repo:
         uis.add(req.repo.ui)
 
+    if (req.earlyoptions['verbose'] or req.earlyoptions['debug']
+            or req.earlyoptions['quiet']):
+        for opt in ('verbose', 'debug', 'quiet'):
+            val = pycompat.bytestr(bool(req.earlyoptions[opt]))
+            for ui_ in uis:
+                ui_.setconfig('ui', opt, val, '--' + opt)
+
     if req.earlyoptions['profile']:
         for ui_ in uis:
             ui_.setconfig('profiling', 'enabled', 'true', '--profile')
@@ -876,8 +883,11 @@
         if options["profile"]:
             profiler.start()
 
+        # if abbreviated version of this were used, take them in account, now
         if options['verbose'] or options['debug'] or options['quiet']:
             for opt in ('verbose', 'debug', 'quiet'):
+                if options[opt] == req.earlyoptions[opt]:
+                    continue
                 val = pycompat.bytestr(bool(options[opt]))
                 for ui_ in uis:
                     ui_.setconfig('ui', opt, val, '--' + opt)
--- a/tests/test-extension.t	Tue Jun 19 19:10:31 2018 +0100
+++ b/tests/test-extension.t	Tue Jun 19 19:18:31 2018 +0100
@@ -9,7 +9,9 @@
   > configitem = registrar.configitem(configtable)
   > configitem(b'tests', b'foo', default=b"Foo")
   > def uisetup(ui):
+  >     ui.debug(b"uisetup called [debug]\\n")
   >     ui.write(b"uisetup called\\n")
+  >     ui.status(b"uisetup called [status]\\n")
   >     ui.flush()
   > def reposetup(ui, repo):
   >     ui.write(b"reposetup called for %s\\n" % os.path.basename(repo.root))
@@ -40,15 +42,29 @@
   $ echo "foobar = $abspath" >> $HGRCPATH
   $ hg foo
   uisetup called
+  uisetup called [status]
   reposetup called for a
   ui == repo.ui
   reposetup called for a (chg !)
   ui == repo.ui (chg !)
   Foo
+  $ hg foo --quiet
+  uisetup called (no-chg !)
+  reposetup called for a (chg !)
+  ui == repo.ui
+  Foo
+  $ hg foo --debug
+  uisetup called [debug] (no-chg !)
+  uisetup called (no-chg !)
+  uisetup called [status] (no-chg !)
+  reposetup called for a (chg !)
+  ui == repo.ui
+  Foo
 
   $ cd ..
   $ hg clone a b
   uisetup called (no-chg !)
+  uisetup called [status] (no-chg !)
   reposetup called for a
   ui == repo.ui
   reposetup called for b
@@ -58,6 +74,7 @@
 
   $ hg bar
   uisetup called (no-chg !)
+  uisetup called [status] (no-chg !)
   Bar
   $ echo 'foobar = !' >> $HGRCPATH
 
@@ -67,6 +84,7 @@
   $ cd a
   $ hg foo
   uisetup called
+  uisetup called [status]
   reposetup called for a
   ui == repo.ui
   reposetup called for a (chg !)