Patchwork [1,of,4] config: extra the core config logic into a private method

login
register
mail settings
Submitter Pierre-Yves David
Date June 25, 2017, 4:34 p.m.
Message ID <290508394c236b288e1b.1498408478@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21699/
State Accepted
Headers show

Comments

Pierre-Yves David - June 25, 2017, 4:34 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1498394074 -7200
#      Sun Jun 25 14:34:34 2017 +0200
# Node ID 290508394c236b288e1b2ebf3d60a28843f9fa00
# Parent  181ca34883e67e99bf6340b5931ac6d5a894092f
# EXP-Topic config.register
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 290508394c23
config: extra the core config logic into a private method

This will make is easier for the other 'configxxx' function to detect unset value.
Yuya Nishihara - June 26, 2017, 12:59 p.m.
On Sun, 25 Jun 2017 18:34:38 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # Date 1498394074 -7200
> #      Sun Jun 25 14:34:34 2017 +0200
> # Node ID 290508394c236b288e1b2ebf3d60a28843f9fa00
> # Parent  181ca34883e67e99bf6340b5931ac6d5a894092f
> # EXP-Topic config.register
> # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
> #              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 290508394c23
> config: extra the core config logic into a private method

Queued these, thanks.

>      def config(self, section, name, default=_unset, untrusted=False):
> +        """return the plain string version of a config"""
> +        value = self._config(section, name, default=default,
> +                             untrusted=untrusted)
> +        if value is _unset:
> +            return None
> +        return value
> +
> +    def _config(self, section, name, default=_unset, untrusted=False):
> +        value = default
>          if isinstance(name, list):
>              alternates = name
> -            # let us ignore the config items in the alternates case for now
> -            if default is _unset:
> -                default = None

I think this comment is still valid. If name is a list, no default would be
taken from the registered defaults.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -439,32 +439,38 @@  class ui(object):
         return self._data(untrusted).source(section, name)
 
     def config(self, section, name, default=_unset, untrusted=False):
+        """return the plain string version of a config"""
+        value = self._config(section, name, default=default,
+                             untrusted=untrusted)
+        if value is _unset:
+            return None
+        return value
+
+    def _config(self, section, name, default=_unset, untrusted=False):
+        value = default
         if isinstance(name, list):
             alternates = name
-            # let us ignore the config items in the alternates case for now
-            if default is _unset:
-                default = None
         else:
             item = self._knownconfig.get(section, {}).get(name)
             if default is _unset:
-                default = None
-                if item is not None:
-                    default = item.default
+                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, 1, 'warn-config-default')
+                self.develwarn(msg, 2, 'warn-config-default')
 
             alternates = [name]
 
         for n in alternates:
-            value = self._data(untrusted).get(section, n, None)
-            if value is not None:
+            candidate = self._data(untrusted).get(section, n, None)
+            if candidate is not None:
+                value = candidate
                 name = n
                 break
-        else:
-            value = default
 
         if self.debugflag and not untrusted and self._reportuntrusted:
             for n in alternates: