# HG changeset patch # User Boris Feld # Date 1529432311 -3600 # Node ID b86664c81833a48a24dd011a6fff141c8e49a040 # Parent 9ee202679a76c17177ebfff0254fec00f46cfbd2 debug: process --debug flag earlier This allow the verbosity level to be set correctly during extension initialization. diff -r 9ee202679a76 -r b86664c81833 mercurial/dispatch.py --- 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) diff -r 9ee202679a76 -r b86664c81833 tests/test-extension.t --- 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 !)