Mercurial > public > mercurial-scm > hg-stable
diff mercurial/commands.py @ 36446:07e207e88b42
showconfig: use set to filter sections and entry names
Before, an entry matching the specified section could be printed twice if the
selector wasn't unique.
"sections" and "items" are renamed because it's hard to distinguish "sections"
from the loop variable "section".
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 21 Feb 2018 23:02:39 +0900 |
parents | a75cab94e936 |
children | 199443c55463 |
line wrap: on
line diff
--- a/mercurial/commands.py Wed Feb 21 22:20:27 2018 +0900 +++ b/mercurial/commands.py Wed Feb 21 23:02:39 2018 +0900 @@ -1693,11 +1693,16 @@ else: raise error.ProgrammingError('unknown rctype: %s' % t) untrusted = bool(opts.get('untrusted')) + + selsections = selentries = [] if values: - sections = [v for v in values if '.' not in v] - items = [v for v in values if '.' in v] - if len(items) > 1 or items and sections: + 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')) + selsections = set(selsections) + selentries = set(selentries) + matched = False for section, name, value in ui.walkconfig(untrusted=untrusted): source = ui.configsource(section, name, untrusted) @@ -1707,18 +1712,17 @@ value = value.replace('\n', '\\n') entryname = section + '.' + name if values: - for v in values: - if v == section: - fm.startitem() - fm.condwrite(ui.debugflag, 'source', '%s: ', source) - fm.write('name value', '%s=%s\n', entryname, value) - matched = True - elif v == entryname: - fm.startitem() - fm.condwrite(ui.debugflag, 'source', '%s: ', source) - fm.write('value', '%s\n', value) - fm.data(name=entryname) - matched = True + 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 else: fm.startitem() fm.condwrite(ui.debugflag, 'source', '%s: ', source)