# HG changeset patch # User Pierre-Yves David # Date 2017-06-25 12:34:34 # Node ID 1aa05203f7f66e8566ce6e92cc3451a9b7ce15c3 # Parent 03eefca3ed33659454184a195b0b7bccd114734a config: extract the core config logic into a private method This will make it easier for the other 'configxxx' function to detect unset value. 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: