config: add defaultvalue template keyword
This patch tries to fix one of the issues mentioned in
issue6014.
This adds a new `defaultvalue` template keyword to be used with
`hg showconfig` to get the default value of the config item.
Differential Revision: https://phab.mercurial-scm.org/D6704
--- a/mercurial/commands.py Thu Aug 01 12:23:07 2019 -0400
+++ b/mercurial/commands.py Thu Aug 01 22:03:52 2019 +0530
@@ -1872,6 +1872,7 @@
for section, name, value in ui.walkconfig(untrusted=untrusted):
source = ui.configsource(section, name, untrusted)
value = pycompat.bytestr(value)
+ defaultvalue = pycompat.bytestr(ui.configdefault(section, name))
if fm.isplain():
source = source or 'none'
value = value.replace('\n', '\\n')
@@ -1881,7 +1882,7 @@
fm.startitem()
fm.condwrite(ui.debugflag, 'source', '%s: ', source)
if uniquesel:
- fm.data(name=entryname)
+ fm.data(name=entryname, defaultvalue=defaultvalue)
fm.write('value', '%s\n', value)
else:
fm.write('name value', '%s=%s\n', entryname, value)
--- a/mercurial/ui.py Thu Aug 01 12:23:07 2019 -0400
+++ b/mercurial/ui.py Thu Aug 01 22:03:52 2019 +0530
@@ -783,6 +783,17 @@
return None
return default
+ def configdefault(self, section, name):
+ """returns the default value of the config item"""
+ item = self._knownconfig.get(section, {}).get(name)
+ itemdefault = None
+ if item is not None:
+ if callable(item.default):
+ itemdefault = item.default()
+ else:
+ itemdefault = item.default
+ return itemdefault
+
def hasconfig(self, section, name, untrusted=False):
return self._data(untrusted).hasitem(section, name)
--- a/tests/test-config.t Thu Aug 01 12:23:07 2019 -0400
+++ b/tests/test-config.t Thu Aug 01 22:03:52 2019 +0530
@@ -70,6 +70,7 @@
$ hg showconfig Section.KeY -Tjson
[
{
+ "defaultvalue": "None",
"name": "Section.KeY",
"source": "*.hgrc:*", (glob)
"value": "Case Sensitive"
@@ -102,6 +103,7 @@
$ hg config empty.source -Tjson
[
{
+ "defaultvalue": "None",
"name": "empty.source",
"source": "",
"value": "value"