This is an archive of the discontinued Mercurial Phabricator instance.

config: add defaultvalue template keyword
ClosedPublic

Authored by navaneeth.suresh on Aug 1 2019, 1:42 PM.

Details

Summary

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.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

durin42 added a subscriber: durin42.Aug 1 2019, 2:38 PM

I like the feature, I'll go ahead and queue it with the str/bytestr thing fixed in flight. Thanks!

mercurial/commands.py
1875

you almost certainly want pycompat.bytestr() here and not str() for py3 compat reasons

This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.
navaneeth.suresh marked an inline comment as done.Aug 2 2019, 4:12 AM
navaneeth.suresh added inline comments.
mercurial/commands.py
1875

thanks for the fix and queuing @durin42.

navaneeth.suresh marked an inline comment as done.Aug 2 2019, 4:26 AM
yuja added a subscriber: yuja.Aug 2 2019, 9:37 AM

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

@yuja Thanks for the review. Will send a follow-up soon.

hg config -T '{defaultvalue}' shows a bunch of entries like <object object at 0x7fc4295c00f0>, which is clearly not something we want to show the user. Also hg config -T json crashes for a similar reason (mercurial.error.ProgrammingError: cannot encode <object object at 0x7fdd1a6a20f0>).

yuja added a comment.Aug 25 2019, 7:38 PM
`hg config -T '{defaultvalue}'` shows a bunch of entries like `<object object at 0x7fc4295c00f0>`, which is clearly not something we want to show the user. Also `hg config -T json` crashes for a similar reason (`mercurial.error.ProgrammingError: cannot encode <object object at 0x7fdd1a6a20f0>`).

Yup. That's mostly because of configitems.dynamicdefault.

Really nice post here getting how to get robux for free hope you guys like it fun here