Patchwork D6704: config: add defaultvalue template keyword

login
register
mail settings
Submitter phabricator
Date Aug. 1, 2019, 6:47 p.m.
Message ID <ec7ac186a58261ecca92c89f4f7fc219@localhost.localdomain>
Download mbox | patch
Permalink /patch/41112/
State Not Applicable
Headers show

Comments

phabricator - Aug. 1, 2019, 6:47 p.m.
Closed by commit rHG51a2e3102db2: config: add defaultvalue template keyword (authored by navaneeth.suresh).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D6704?vs=16101&id=16103#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6704?vs=16101&id=16103

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

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: durin42, mercurial-devel
Yuya Nishihara - Aug. 2, 2019, 1:35 p.m.
> +    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.
phabricator - Aug. 2, 2019, 1:37 p.m.
yuja added a comment.


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

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

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