Patchwork [3,of,3] configitems: support alias in ui.config

login
register
mail settings
Submitter David Demelier
Date June 27, 2017, 6:17 p.m.
Message ID <3f255005be78f8ad9c03.1498587422@kiwi.home>
Download mbox | patch
Permalink /patch/21786/
State Accepted
Headers show

Comments

David Demelier - June 27, 2017, 6:17 p.m.
# HG changeset patch
# User David Demelier <markand@malikania.fr>
# Date 1498586402 -7200
#      Tue Jun 27 20:00:02 2017 +0200
# Node ID 3f255005be78f8ad9c039e53ca5f520143963a46
# Parent  9eab1b51385ab89e3fdd304ce3da68db4959a48e
configitems: support alias in ui.config
Augie Fackler - June 27, 2017, 9:08 p.m.
On Tue, Jun 27, 2017 at 08:17:02PM +0200, David Demelier wrote:
> # HG changeset patch
> # User David Demelier <markand@malikania.fr>
> # Date 1498586402 -7200
> #      Tue Jun 27 20:00:02 2017 +0200
> # Node ID 3f255005be78f8ad9c039e53ca5f520143963a46
> # Parent  9eab1b51385ab89e3fdd304ce3da68db4959a48e
> configitems: support alias in ui.config

queued, thanks

Patch

diff -r 9eab1b51385a -r 3f255005be78 mercurial/ui.py
--- a/mercurial/ui.py	Tue Jun 20 12:22:52 2017 +0200
+++ b/mercurial/ui.py	Tue Jun 27 20:00:02 2017 +0200
@@ -448,36 +448,37 @@ 
 
     def _config(self, section, name, default=_unset, untrusted=False):
         value = default
-        if isinstance(name, list):
-            alternates = name
-        else:
-            item = self._knownconfig.get(section, {}).get(name)
-            if default is _unset:
-                if item is None:
-                    value = default
-                else:
-                    value = item.default
-            elif item is not None:
-                msg = ("specifying a default value for a registered "
-                       "config item: '%s.%s' '%s'")
-                msg %= (section, name, default)
-                self.develwarn(msg, 2, 'warn-config-default')
+        item = self._knownconfig.get(section, {}).get(name)
+        alternates = [(section, name)]
+
+        if item is not None and item.alias is not None:
+            alternates = alternates + item.alias
 
-            alternates = [name]
+        if default is _unset:
+            if item is None:
+                value = default
+            else:
+                value = item.default
+        elif item is not None:
+            msg = ("specifying a default value for a registered "
+                   "config item: '%s.%s' '%s'")
+            msg %= (section, name, default)
+            self.develwarn(msg, 2, 'warn-config-default')
 
-        for n in alternates:
-            candidate = self._data(untrusted).get(section, n, None)
+        for s, n in alternates:
+            candidate = self._data(untrusted).get(s, n, None)
             if candidate is not None:
                 value = candidate
+                section = s
                 name = n
                 break
 
         if self.debugflag and not untrusted and self._reportuntrusted:
-            for n in alternates:
-                uvalue = self._ucfg.get(section, n)
+            for s, n in alternates:
+                uvalue = self._ucfg.get(s, n)
                 if uvalue is not None and uvalue != value:
                     self.debug("ignoring untrusted configuration option "
-                               "%s.%s = %s\n" % (section, n, uvalue))
+                               "%s.%s = %s\n" % (s, n, uvalue))
         return value
 
     def configsuboptions(self, section, name, default=_unset, untrusted=False):
diff -r 9eab1b51385a -r 3f255005be78 tests/test-config.t
--- a/tests/test-config.t	Tue Jun 20 12:22:52 2017 +0200
+++ b/tests/test-config.t	Tue Jun 27 20:00:02 2017 +0200
@@ -178,3 +178,20 @@ 
 
   $ PAGER=p1 hg config --debug --config pager.pager=p2 | grep 'pager\.pager'
   --config: pager.pager=p2
+
+verify that aliases are searched as well
+
+  $ cd ..
+  $ hg init aliastest
+  $ cd aliastest
+  $ cat > .hg/hgrc << EOF
+  > [ui]
+  > user = repo user
+  > EOF
+  $ echo "" > $HGRCPATH
+  $ touch index
+  $ unset HGUSER
+  $ hg ci -Am test
+  adding index
+  $ hg log --template '{author}\n'
+  repo user