Patchwork D9759: ui: add a "config_default" method

login
register
mail settings
Submitter phabricator
Date Jan. 14, 2021, 4:05 a.m.
Message ID <differential-rev-PHID-DREV-56qfu4yvwnp7bwioax7z-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48069/
State Superseded
Headers show

Comments

phabricator - Jan. 14, 2021, 4:05 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9759

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -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.