D6704: config: add defaultvalue template keyword

Yuya Nishihara yuya at tcha.org
Fri Aug 2 09:35:33 EDT 2019


> +    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

Need to handle configitems.dynamicdefault.

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

We'll probably want to keep None as itself. It's useless if an empty
default were mapped to truthy value, "None".

> @@ -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)

Missed fm.data() for the else case. fm.data(defaultvalue=...) can be moved
out of the if block.


More information about the Mercurial-devel mailing list