[PATCH 2 of 4] config: give a useful hint of source for the most common command line settings

Mads Kiilerich mads at kiilerich.com
Tue Mar 18 20:45:24 CDT 2014


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1395193504 -3600
#      Wed Mar 19 02:45:04 2014 +0100
# Node ID b9673d596335044e9cb7b1814c895e8a83bc10d4
# Parent  1a8b79587d4e9258c0850e001f393d34f56c6906
config: give a useful hint of source for the most common command line settings

'hg showconfig --debug' will instead of:
  none: ui.verbose=False
give the better hint:
  --verbose: ui.verbose=False

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -40,7 +40,7 @@ def dispatch(req):
         if not req.ui:
             req.ui = uimod.ui()
         if '--traceback' in req.args:
-            req.ui.setconfig('ui', 'traceback', 'on')
+            req.ui.setconfig('ui', 'traceback', 'on', '--traceback')
 
         # set ui streams from the request
         if req.fin:
@@ -104,7 +104,7 @@ def _runcatch(req):
                 # copy configs that were passed on the cmdline (--config) to
                 # the repo ui
                 for cfg in cfgs:
-                    req.repo.ui.setconfig(*cfg)
+                    req.repo.ui.setconfig(*cfg, source='--config')
 
             # if we are in HGPLAIN mode, then disable custom debugging
             debugger = ui.config("ui", "debugger")
@@ -518,7 +518,7 @@ def _parseconfig(ui, config):
             section, name = name.split('.', 1)
             if not section or not name:
                 raise IndexError
-            ui.setconfig(section, name, value)
+            ui.setconfig(section, name, value, '--config')
             configs.append((section, name, value))
         except (IndexError, ValueError):
             raise util.Abort(_('malformed --config option: %r '
@@ -735,19 +735,19 @@ def _dispatch(req):
         for opt in ('verbose', 'debug', 'quiet'):
             val = str(bool(options[opt]))
             for ui_ in uis:
-                ui_.setconfig('ui', opt, val)
+                ui_.setconfig('ui', opt, val, '--' + opt)
 
     if options['traceback']:
         for ui_ in uis:
-            ui_.setconfig('ui', 'traceback', 'on')
+            ui_.setconfig('ui', 'traceback', 'on', '--traceback')
 
     if options['noninteractive']:
         for ui_ in uis:
-            ui_.setconfig('ui', 'interactive', 'off')
+            ui_.setconfig('ui', 'interactive', 'off', '-y')
 
     if cmdoptions.get('insecure', False):
         for ui_ in uis:
-            ui_.setconfig('web', 'cacerts', '')
+            ui_.setconfig('web', 'cacerts', '', '--insecure')
 
     if options['version']:
         return commands.version_(ui)
@@ -773,7 +773,7 @@ def _dispatch(req):
                 repo = hg.repository(ui, path=path)
                 if not repo.local():
                     raise util.Abort(_("repository '%s' is not local") % path)
-                repo.ui.setconfig("bundle", "mainreporoot", repo.root)
+                repo.ui.setconfig("bundle", "mainreporoot", repo.root, 'repo')
             except error.RequirementError:
                 raise
             except error.RepoError:
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -157,9 +157,9 @@ class ui(object):
         self._tcfg.restore(data[1])
         self._ucfg.restore(data[2])
 
-    def setconfig(self, section, name, value):
+    def setconfig(self, section, name, value, source=''):
         for cfg in (self._ocfg, self._tcfg, self._ucfg):
-            cfg.set(section, name, value)
+            cfg.set(section, name, value, source)
         self.fixconfig(section=section)
 
     def _data(self, untrusted):
diff --git a/tests/test-hgrc.t b/tests/test-hgrc.t
--- a/tests/test-hgrc.t
+++ b/tests/test-hgrc.t
@@ -141,7 +141,7 @@ customized hgrc
   $ hg showconfig
   read config from: $TESTTMP/hgrc
   $TESTTMP/hgrc:13: alias.log=log -g
-  none: bundle.mainreporoot=$TESTTMP
+  repo: bundle.mainreporoot=$TESTTMP
   $TESTTMP/hgrc:11: defaults.identify=-n
   $TESTTMP/hgrc:2: ui.debug=true
   $TESTTMP/hgrc:3: ui.fallbackencoding=ASCII
@@ -157,11 +157,11 @@ plain hgrc
   $ HGPLAIN=; export HGPLAIN
   $ hg showconfig --config ui.traceback=True --debug
   read config from: $TESTTMP/hgrc
-  none: bundle.mainreporoot=$TESTTMP
-  none: ui.traceback=True
-  none: ui.verbose=False
-  none: ui.debug=True
-  none: ui.quiet=False
+  repo: bundle.mainreporoot=$TESTTMP
+  --config: ui.traceback=True
+  --verbose: ui.verbose=False
+  --debug: ui.debug=True
+  --quiet: ui.quiet=False
 
 plain mode with exceptions
 
@@ -175,29 +175,29 @@ plain mode with exceptions
   $ hg showconfig --config ui.traceback=True --debug
   plain: True
   read config from: $TESTTMP/hgrc
-  none: bundle.mainreporoot=$TESTTMP
+  repo: bundle.mainreporoot=$TESTTMP
   $TESTTMP/hgrc:15: extensions.plain=./plain.py
-  none: ui.traceback=True
-  none: ui.verbose=False
-  none: ui.debug=True
-  none: ui.quiet=False
+  --config: ui.traceback=True
+  --verbose: ui.verbose=False
+  --debug: ui.debug=True
+  --quiet: ui.quiet=False
   $ unset HGPLAIN
   $ hg showconfig --config ui.traceback=True --debug
   plain: True
   read config from: $TESTTMP/hgrc
-  none: bundle.mainreporoot=$TESTTMP
+  repo: bundle.mainreporoot=$TESTTMP
   $TESTTMP/hgrc:15: extensions.plain=./plain.py
-  none: ui.traceback=True
-  none: ui.verbose=False
-  none: ui.debug=True
-  none: ui.quiet=False
+  --config: ui.traceback=True
+  --verbose: ui.verbose=False
+  --debug: ui.debug=True
+  --quiet: ui.quiet=False
   $ HGPLAINEXCEPT=i18n; export HGPLAINEXCEPT
   $ hg showconfig --config ui.traceback=True --debug
   plain: True
   read config from: $TESTTMP/hgrc
-  none: bundle.mainreporoot=$TESTTMP
+  repo: bundle.mainreporoot=$TESTTMP
   $TESTTMP/hgrc:15: extensions.plain=./plain.py
-  none: ui.traceback=True
-  none: ui.verbose=False
-  none: ui.debug=True
-  none: ui.quiet=False
+  --config: ui.traceback=True
+  --verbose: ui.verbose=False
+  --debug: ui.debug=True
+  --quiet: ui.quiet=False


More information about the Mercurial-devel mailing list