showconfig: allow multiple section.name selectors (issue5797)
authorYuya Nishihara <yuya@tcha.org>
Wed, 21 Feb 2018 22:47:47 +0900
changeset 36447 199443c55463
parent 36446 07e207e88b42
child 36448 d26b0bedfaa4
showconfig: allow multiple section.name selectors (issue5797) This seems useful and we can disambiguate the output format solely by the type of the command arguments.
mercurial/commands.py
tests/test-hgrc.t
--- a/mercurial/commands.py	Wed Feb 21 23:02:39 2018 +0900
+++ b/mercurial/commands.py	Wed Feb 21 22:47:47 2018 +0900
@@ -1632,7 +1632,7 @@
     of that config item.
 
     With multiple arguments, print names and values of all config
-    items with matching section names.
+    items with matching section names or section.names.
 
     With --edit, start an editor on the user-level config file. With
     --global, edit the system-wide config file. With --local, edit the
@@ -1698,8 +1698,7 @@
     if values:
         selsections = [v for v in values if '.' not in v]
         selentries = [v for v in values if '.' in v]
-        if len(selentries) > 1 or selentries and selsections:
-            raise error.Abort(_('only one config item permitted'))
+    uniquesel = (len(selentries) == 1 and not selsections)
     selsections = set(selsections)
     selentries = set(selentries)
 
@@ -1711,23 +1710,16 @@
             source = source or 'none'
             value = value.replace('\n', '\\n')
         entryname = section + '.' + name
-        if values:
-            if section in selsections:
-                fm.startitem()
-                fm.condwrite(ui.debugflag, 'source', '%s: ', source)
-                fm.write('name value', '%s=%s\n', entryname, value)
-                matched = True
-            elif entryname in selentries:
-                fm.startitem()
-                fm.condwrite(ui.debugflag, 'source', '%s: ', source)
-                fm.write('value', '%s\n', value)
-                fm.data(name=entryname)
-                matched = True
+        if values and not (section in selsections or entryname in selentries):
+            continue
+        fm.startitem()
+        fm.condwrite(ui.debugflag, 'source', '%s: ', source)
+        if uniquesel:
+            fm.data(name=entryname)
+            fm.write('value', '%s\n', value)
         else:
-            fm.startitem()
-            fm.condwrite(ui.debugflag, 'source', '%s: ', source)
             fm.write('name value', '%s=%s\n', entryname, value)
-            matched = True
+        matched = True
     fm.end()
     if matched:
         return 0
--- a/tests/test-hgrc.t	Wed Feb 21 23:02:39 2018 +0900
+++ b/tests/test-hgrc.t	Wed Feb 21 22:47:47 2018 +0900
@@ -129,14 +129,13 @@
   $ hg showconfig alias alias
   alias.log=log -g
   $ hg showconfig alias.log alias.log
-  abort: only one config item permitted
-  [255]
+  alias.log=log -g
   $ hg showconfig alias defaults.identify
-  abort: only one config item permitted
-  [255]
+  alias.log=log -g
+  defaults.identify=-n
   $ hg showconfig alias.log defaults.identify
-  abort: only one config item permitted
-  [255]
+  alias.log=log -g
+  defaults.identify=-n
 
 HGPLAIN