Patchwork [2,of,2] showconfig: allow multiple section.name selectors (issue5797)

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 21, 2018, 2:34 p.m.
Message ID <46e1a9cc97996cc1469e.1519223647@mimosa>
Download mbox | patch
Permalink /patch/28187/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 21, 2018, 2:34 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519220867 -32400
#      Wed Feb 21 22:47:47 2018 +0900
# Node ID 46e1a9cc97996cc1469efabdeeb4a51ccc552413
# Parent  11003771245a19f65107b141a9c1adc9461d43ea
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.
Augie Fackler - Feb. 26, 2018, 4:15 a.m.
On Wed, Feb 21, 2018 at 11:34:07PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1519220867 -32400
> #      Wed Feb 21 22:47:47 2018 +0900
> # Node ID 46e1a9cc97996cc1469efabdeeb4a51ccc552413
> # Parent  11003771245a19f65107b141a9c1adc9461d43ea
> showconfig: allow multiple section.name selectors (issue5797)

queued, thanks

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1631,7 +1631,7 @@  def config(ui, repo, *values, **opts):
     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
@@ -1697,8 +1697,7 @@  def config(ui, repo, *values, **opts):
     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)
 
@@ -1710,23 +1709,16 @@  def config(ui, repo, *values, **opts):
             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
diff --git a/tests/test-hgrc.t b/tests/test-hgrc.t
--- a/tests/test-hgrc.t
+++ b/tests/test-hgrc.t
@@ -129,14 +129,13 @@  showconfig with multiple arguments
   $ 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