Patchwork [2,of,3,STABLE] config: add support for defaultvalue of list of printable elements

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 27, 2019, 4:12 a.m.
Message ID <a3e8a9303f3eef7f529c.1572149574@mimosa>
Download mbox | patch
Permalink /patch/42596/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 27, 2019, 4:12 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1572147412 -32400
#      Sun Oct 27 12:36:52 2019 +0900
# Branch stable
# Node ID a3e8a9303f3eef7f529c0695d24d81b7c01a5344
# Parent  94624c0871a1a5f0ece06302a14dff6b9635d722
config: add support for defaultvalue of list of printable elements

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2269,6 +2269,10 @@  def config(ui, repo, *values, **opts):
             fm.write(b'name value', b'%s=%s\n', entryname, value)
         if formatter.isprintable(defaultvalue):
             fm.data(defaultvalue=defaultvalue)
+        elif isinstance(defaultvalue, list) and all(
+            formatter.isprintable(e) for e in defaultvalue
+        ):
+            fm.data(defaultvalue=fm.formatlist(defaultvalue, name=b'value'))
         # TODO: no idea how to process unsupported defaultvalue types
         matched = True
     fm.end()
diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -186,6 +186,7 @@  Test config default of various types:
   $ hg config --config commands.show.aliasprefix= commands -Tjson
   [
    {
+    "defaultvalue": [],
     "name": "commands.show.aliasprefix",
     "source": "--config",
     "value": ""
@@ -193,7 +194,7 @@  Test config default of various types:
   ]
   $ hg config --config commands.show.aliasprefix= commands -T'json(defaultvalue)'
   [
-   {"defaultvalue": ""}
+   {"defaultvalue": []}
   ]
   $ hg config --config commands.show.aliasprefix= commands -T'{defaultvalue}\n'
   
@@ -203,6 +204,7 @@  Test config default of various types:
   $ hg config --config progress.format= progress -Tjson
   [
    {
+    "defaultvalue": ["topic", "bar", "number", "estimate"],
     "name": "progress.format",
     "source": "--config",
     "value": ""
@@ -210,10 +212,10 @@  Test config default of various types:
   ]
   $ hg config --config progress.format= progress -T'json(defaultvalue)'
   [
-   {"defaultvalue": ""}
+   {"defaultvalue": ["topic", "bar", "number", "estimate"]}
   ]
   $ hg config --config progress.format= progress -T'{defaultvalue}\n'
-  
+  topic bar number estimate
 
  int