Patchwork D6704: config: add defaultvalue template keyword

login
register
mail settings
Submitter phabricator
Date Aug. 1, 2019, 5:43 p.m.
Message ID <differential-rev-PHID-DREV-jrgdm2dpkhylm2cenk6z-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41106/
State Superseded
Headers show

Comments

phabricator - Aug. 1, 2019, 5:43 p.m.
navaneeth.suresh created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

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

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/commands.py
  mercurial/ui.py
  tests/test-config.t

CHANGE DETAILS




To: navaneeth.suresh, #hg-reviewers
Cc: mercurial-devel
phabricator - Aug. 1, 2019, 6:38 p.m.
durin42 added a comment.


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

INLINE COMMENTS

> commands.py:1875
>          value = pycompat.bytestr(value)
> +        defaultvalue = str(ui.configdefault(section, name))
>          if fm.isplain():

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

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6704/new/

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

To: navaneeth.suresh, #hg-reviewers
Cc: durin42, mercurial-devel
phabricator - Aug. 2, 2019, 8:12 a.m.
navaneeth.suresh added inline comments.
navaneeth.suresh marked an inline comment as done.

INLINE COMMENTS

> durin42 wrote in commands.py:1875
> you almost certainly want `pycompat.bytestr()` here and not `str()` for py3 compat reasons

thanks for the fix and queuing @durin42.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6704/new/

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

To: navaneeth.suresh, #hg-reviewers
Cc: durin42, mercurial-devel
phabricator - Aug. 3, 2019, 6:01 a.m.
navaneeth.suresh added a comment.


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

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6704/new/

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

To: navaneeth.suresh, #hg-reviewers
Cc: yuja, durin42, mercurial-devel
phabricator - Aug. 25, 2019, 10:12 p.m.
martinvonz added a comment.


  `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>`).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6704/new/

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

To: navaneeth.suresh, #hg-reviewers
Cc: martinvonz, yuja, durin42, mercurial-devel
Yuya Nishihara - Aug. 25, 2019, 11:11 p.m.
>   `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.
phabricator - Aug. 25, 2019, 11:38 p.m.
yuja added a comment.


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

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6704/new/

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

To: navaneeth.suresh, #hg-reviewers
Cc: martinvonz, yuja, durin42, mercurial-devel
phabricator - Oct. 21, 2021, 7:44 a.m.
Herald added a subscriber: mercurial-patches.
ryancoop987 added a comment.


  Really nice post here getting how to get robux for free <https://freerobuxtips.com> hope you guys like it fun here

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6704/new/

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

To: navaneeth.suresh, #hg-reviewers
Cc: mercurial-patches, ryancoop987, martinvonz, yuja, durin42, mercurial-devel

Patch

diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -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"
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -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)
 
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 = str(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)