changeset 33058:1aa05203f7f6

config: extract the core config logic into a private method This will make it easier for the other 'configxxx' function to detect unset value.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 25 Jun 2017 14:34:34 +0200
parents 03eefca3ed33
children 1dc2ffe0123b
files mercurial/ui.py
diffstat 1 files changed, 17 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Fri Jun 23 01:38:10 2017 +0200
+++ b/mercurial/ui.py	Sun Jun 25 14:34:34 2017 +0200
@@ -439,32 +439,38 @@
         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: