Patchwork [3,of,8] configitems: get default values from the central registry when available

login
register
mail settings
Submitter Pierre-Yves David
Date June 21, 2017, 8:55 a.m.
Message ID <a9ce5ac5b1ece7edbf8f.1498035304@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21587/
State Accepted
Headers show

Comments

Pierre-Yves David - June 21, 2017, 8:55 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1497694528 -7200
#      Sat Jun 17 12:15:28 2017 +0200
# Node ID a9ce5ac5b1ece7edbf8fb7382d6104516c4a590a
# Parent  8610aec63456a82a48a050fb73f1d80d1e49bcc1
# 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 a9ce5ac5b1ec
configitems: get default values from the central registry when available

We do not have any registered config yet, but we are now ready to use them.

For now we ignore this feature for config access with "alternates". On the long
run, we expect alternates to be handled as "aliases" by the config item
themself.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -439,11 +439,17 @@  class ui(object):
         return self._data(untrusted).source(section, name)
 
     def config(self, section, name, default=_unset, untrusted=False):
-        if default is _unset:
-            default = None
         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:
+            if default is _unset:
+                default = None
+                item = self._knownconfig.get(section, {}).get(name)
+                if item is not None:
+                    default = item.default
             alternates = [name]
 
         for n in alternates: