changeset 47088:3e381eb557f3

config: add --source option to include source of value Showing the source of each config option is quite useful and not something the user should have to reach for the `--debug` flag for. I updates documentation and tests, except for one place in `test-hgrc.t` where I thought the test might have been intended to also test that `--debug` results in `ui.quiet` etc being test. Differential Revision: https://phab.mercurial-scm.org/D10668
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 04 May 2021 08:54:28 -0700
parents d90f6237b3aa
children 4c041c71ec01
files mercurial/commands.py mercurial/helptext/config.txt relnotes/next tests/test-completion.t tests/test-config.t tests/test-hgrc.t tests/test-lfs-bundle.t tests/test-phabricator.t
diffstat 8 files changed, 22 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Tue May 04 10:49:32 2021 -0700
+++ b/mercurial/commands.py	Tue May 04 08:54:28 2021 -0700
@@ -2202,6 +2202,7 @@
         (b'u', b'untrusted', None, _(b'show untrusted configuration options')),
         (b'e', b'edit', None, _(b'edit user config')),
         (b'l', b'local', None, _(b'edit repository config')),
+        (b'', b'source', None, _(b'show source of configuration value')),
         (
             b'',
             b'shared',
@@ -2232,7 +2233,7 @@
     --global, edit the system-wide config file. With --local, edit the
     repository-level config file.
 
-    With --debug, the source (filename and line number) is printed
+    With --source, the source (filename and line number) is printed
     for each config item.
 
     See :hg:`help config` for more information about config files.
@@ -2335,6 +2336,7 @@
     selentries = set(selentries)
 
     matched = False
+    show_source = ui.debugflag or opts.get(b'source')
     for section, name, value in ui.walkconfig(untrusted=untrusted):
         source = ui.configsource(section, name, untrusted)
         value = pycompat.bytestr(value)
@@ -2346,7 +2348,7 @@
         if values and not (section in selsections or entryname in selentries):
             continue
         fm.startitem()
-        fm.condwrite(ui.debugflag, b'source', b'%s: ', source)
+        fm.condwrite(show_source, b'source', b'%s: ', source)
         if uniquesel:
             fm.data(name=entryname)
             fm.write(b'value', b'%s\n', value)
--- a/mercurial/helptext/config.txt	Tue May 04 10:49:32 2021 -0700
+++ b/mercurial/helptext/config.txt	Tue May 04 08:54:28 2021 -0700
@@ -5,7 +5,7 @@
 ===============
 
 If you're having problems with your configuration,
-:hg:`config --debug` can help you understand what is introducing
+:hg:`config --source` can help you understand what is introducing
 a setting into your environment.
 
 See :hg:`help config.syntax` and :hg:`help config.files`
--- a/relnotes/next	Tue May 04 10:49:32 2021 -0700
+++ b/relnotes/next	Tue May 04 08:54:28 2021 -0700
@@ -1,5 +1,8 @@
 == New Features ==
- 
+
+ * `hg config` now has a `--source` option to show where each
+   configuration value comes from.
+
 
 == Default Format Change ==
 
--- a/tests/test-completion.t	Tue May 04 10:49:32 2021 -0700
+++ b/tests/test-completion.t	Tue May 04 08:54:28 2021 -0700
@@ -262,7 +262,7 @@
   cat: output, rev, decode, include, exclude, template
   clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure
   commit: addremove, close-branch, amend, secret, edit, force-close-branch, interactive, include, exclude, message, logfile, date, user, subrepos
-  config: untrusted, edit, local, shared, non-shared, global, template
+  config: untrusted, edit, local, source, shared, non-shared, global, template
   continue: dry-run
   copy: forget, after, at-rev, force, include, exclude, dry-run
   debugancestor: 
--- a/tests/test-config.t	Tue May 04 10:49:32 2021 -0700
+++ b/tests/test-config.t	Tue May 04 08:54:28 2021 -0700
@@ -277,8 +277,7 @@
   > emptysource = `pwd`/emptysource.py
   > EOF
 
-  $ hg config --debug empty.source
-  read config from: * (glob)
+  $ hg config --source empty.source
   none: value
   $ hg config empty.source -Tjson
   [
@@ -349,16 +348,16 @@
 
 config affected by environment variables
 
-  $ EDITOR=e1 VISUAL=e2 hg config --debug | grep 'ui\.editor'
+  $ EDITOR=e1 VISUAL=e2 hg config --source | grep 'ui\.editor'
   $VISUAL: ui.editor=e2
 
-  $ VISUAL=e2 hg config --debug --config ui.editor=e3 | grep 'ui\.editor'
+  $ VISUAL=e2 hg config --source --config ui.editor=e3 | grep 'ui\.editor'
   --config: ui.editor=e3
 
-  $ PAGER=p1 hg config --debug | grep 'pager\.pager'
+  $ PAGER=p1 hg config --source | grep 'pager\.pager'
   $PAGER: pager.pager=p1
 
-  $ PAGER=p1 hg config --debug --config pager.pager=p2 | grep 'pager\.pager'
+  $ PAGER=p1 hg config --source --config pager.pager=p2 | grep 'pager\.pager'
   --config: pager.pager=p2
 
 verify that aliases are evaluated as well
--- a/tests/test-hgrc.t	Tue May 04 10:49:32 2021 -0700
+++ b/tests/test-hgrc.t	Tue May 04 08:54:28 2021 -0700
@@ -253,9 +253,8 @@
   > [paths]
   > foo = bar
   > EOF
-  $ hg showconfig --debug paths
+  $ hg showconfig --source paths
   plain: True
-  read config from: $TESTTMP/hgrc
   $TESTTMP/hgrc:17: paths.foo=$TESTTMP/bar
 
 Test we can skip the user configuration
--- a/tests/test-lfs-bundle.t	Tue May 04 10:49:32 2021 -0700
+++ b/tests/test-lfs-bundle.t	Tue May 04 08:54:28 2021 -0700
@@ -101,7 +101,7 @@
 #if windows
   $ unset LOCALAPPDATA
   $ unset APPDATA
-  $ HGRCPATH= hg config lfs --debug
+  $ HGRCPATH= hg config lfs --source
   abort: unknown lfs usercache location
   (define LOCALAPPDATA or APPDATA in the environment, or set lfs.usercache)
   [255]
@@ -109,7 +109,7 @@
 
 #if osx
   $ unset HOME
-  $ HGRCPATH= hg config lfs --debug
+  $ HGRCPATH= hg config lfs --source
   abort: unknown lfs usercache location
   (define HOME in the environment, or set lfs.usercache)
   [255]
@@ -118,7 +118,7 @@
 #if no-windows no-osx
   $ unset XDG_CACHE_HOME
   $ unset HOME
-  $ HGRCPATH= hg config lfs --debug
+  $ HGRCPATH= hg config lfs --source
   abort: unknown lfs usercache location
   (define XDG_CACHE_HOME or HOME in the environment, or set lfs.usercache)
   [255]
--- a/tests/test-phabricator.t	Tue May 04 10:49:32 2021 -0700
+++ b/tests/test-phabricator.t	Tue May 04 08:54:28 2021 -0700
@@ -509,9 +509,8 @@
   
 A bad .arcconfig doesn't error out
   $ echo 'garbage' > .arcconfig
-  $ hg config phabricator --debug
+  $ hg config phabricator --source
   invalid JSON in $TESTTMP/repo/.arcconfig
-  read config from: */.hgrc (glob)
   */.hgrc:*: phabricator.debug=True (glob)
   $TESTTMP/repo/.hg/hgrc:*: phabricator.url=https://phab.mercurial-scm.org/ (glob)
   $TESTTMP/repo/.hg/hgrc:*: phabricator.callsign=HG (glob)
@@ -524,8 +523,7 @@
   > EOF
   $ cp $TESTDIR/../.arcconfig .
   $ mv .hg/hgrc .hg/hgrc.bak
-  $ hg config phabricator --debug
-  read config from: */.hgrc (glob)
+  $ hg config phabricator --source
   */.hgrc:*: phabricator.debug=True (glob)
   $TESTTMP/repo/.arcconfig: phabricator.callsign=HG
   $TESTTMP/repo/.arcconfig: phabricator.url=https://phab.mercurial-scm.org/
@@ -536,8 +534,7 @@
   > url = local
   > callsign = local
   > EOF
-  $ hg config phabricator --debug
-  read config from: */.hgrc (glob)
+  $ hg config phabricator --source
   */.hgrc:*: phabricator.debug=True (glob)
   $TESTTMP/repo/.hg/hgrc:*: phabricator.url=local (glob)
   $TESTTMP/repo/.hg/hgrc:*: phabricator.callsign=local (glob)