Mercurial > hg
changeset 46267:b9b37418ac7e
ui: add a "config_default" method
This allow code to access the expected value for a config. This is useful in the
context of dynamic default value, and short term it will be useful to write
dynamically "correct" code.
Differential Revision: https://phab.mercurial-scm.org/D9759
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 13 Jan 2021 18:29:19 +0100 |
parents | e8b0c519dfb3 |
children | 832a6a2efe4f |
files | mercurial/ui.py |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/ui.py Thu Jan 14 11:46:30 2021 +0100 +++ b/mercurial/ui.py Wed Jan 13 18:29:19 2021 +0100 @@ -673,6 +673,18 @@ ) return value + def config_default(self, section, name): + """return the default value for a config option + + The default is returned "raw", for example if it is a callable, the + callable was not called. + """ + item = self._knownconfig.get(section, {}).get(name) + + if item is None: + raise KeyError((section, name)) + return item.default + def configsuboptions(self, section, name, default=_unset, untrusted=False): """Get a config option and all sub-options.