[PATCH 2 of 2] debug: process --debug flag earlier
Boris Feld
boris.feld at octobus.net
Tue Jul 3 13:49:47 EDT 2018
# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1529432311 -3600
# Tue Jun 19 19:18:31 2018 +0100
# Node ID 53221514bc635fc3b8687db48de3e948b075e84c
# Parent d283976aa9a2b35631c749facc0290dd9ea11c30
# EXP-Topic earlydebug
# Available At https://bitbucket.org/octobus/mercurial-devel/
# hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 53221514bc63
debug: process --debug flag earlier
This allow the verbosity level to be set correctly during extension
initialization.
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -811,6 +811,13 @@ def _dispatch(req):
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 @@ def _dispatch(req):
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 --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -9,7 +9,9 @@ Test basic extension support
> 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 @@ Test basic extension support
$ 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 @@ Test basic extension support
$ hg bar
uisetup called (no-chg !)
+ uisetup called [status] (no-chg !)
Bar
$ echo 'foobar = !' >> $HGRCPATH
@@ -67,6 +84,7 @@ module/__init__.py-style
$ cd a
$ hg foo
uisetup called
+ uisetup called [status]
reposetup called for a
ui == repo.ui
reposetup called for a (chg !)
More information about the Mercurial-devel
mailing list