Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 47088:3e381eb557f3
config: add --source option to include source of value
Showing the source of each config option is quite useful and not
something the user should have to reach for the `--debug` flag for.
I updates documentation and tests, except for one place in
`test-hgrc.t` where I thought the test might have been intended to
also test that `--debug` results in `ui.quiet` etc being test.
Differential Revision: https://phab.mercurial-scm.org/D10668
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 04 May 2021 08:54:28 -0700 |
parents | 820fe29d0fd8 |
children | 294a0aa51b8b |
comparison
equal
deleted
inserted
replaced
47087:d90f6237b3aa | 47088:3e381eb557f3 |
---|---|
2200 b'config|showconfig|debugconfig', | 2200 b'config|showconfig|debugconfig', |
2201 [ | 2201 [ |
2202 (b'u', b'untrusted', None, _(b'show untrusted configuration options')), | 2202 (b'u', b'untrusted', None, _(b'show untrusted configuration options')), |
2203 (b'e', b'edit', None, _(b'edit user config')), | 2203 (b'e', b'edit', None, _(b'edit user config')), |
2204 (b'l', b'local', None, _(b'edit repository config')), | 2204 (b'l', b'local', None, _(b'edit repository config')), |
2205 (b'', b'source', None, _(b'show source of configuration value')), | |
2205 ( | 2206 ( |
2206 b'', | 2207 b'', |
2207 b'shared', | 2208 b'shared', |
2208 None, | 2209 None, |
2209 _(b'edit shared source repository config (EXPERIMENTAL)'), | 2210 _(b'edit shared source repository config (EXPERIMENTAL)'), |
2230 | 2231 |
2231 With --edit, start an editor on the user-level config file. With | 2232 With --edit, start an editor on the user-level config file. With |
2232 --global, edit the system-wide config file. With --local, edit the | 2233 --global, edit the system-wide config file. With --local, edit the |
2233 repository-level config file. | 2234 repository-level config file. |
2234 | 2235 |
2235 With --debug, the source (filename and line number) is printed | 2236 With --source, the source (filename and line number) is printed |
2236 for each config item. | 2237 for each config item. |
2237 | 2238 |
2238 See :hg:`help config` for more information about config files. | 2239 See :hg:`help config` for more information about config files. |
2239 | 2240 |
2240 .. container:: verbose | 2241 .. container:: verbose |
2333 uniquesel = len(selentries) == 1 and not selsections | 2334 uniquesel = len(selentries) == 1 and not selsections |
2334 selsections = set(selsections) | 2335 selsections = set(selsections) |
2335 selentries = set(selentries) | 2336 selentries = set(selentries) |
2336 | 2337 |
2337 matched = False | 2338 matched = False |
2339 show_source = ui.debugflag or opts.get(b'source') | |
2338 for section, name, value in ui.walkconfig(untrusted=untrusted): | 2340 for section, name, value in ui.walkconfig(untrusted=untrusted): |
2339 source = ui.configsource(section, name, untrusted) | 2341 source = ui.configsource(section, name, untrusted) |
2340 value = pycompat.bytestr(value) | 2342 value = pycompat.bytestr(value) |
2341 defaultvalue = ui.configdefault(section, name) | 2343 defaultvalue = ui.configdefault(section, name) |
2342 if fm.isplain(): | 2344 if fm.isplain(): |
2344 value = value.replace(b'\n', b'\\n') | 2346 value = value.replace(b'\n', b'\\n') |
2345 entryname = section + b'.' + name | 2347 entryname = section + b'.' + name |
2346 if values and not (section in selsections or entryname in selentries): | 2348 if values and not (section in selsections or entryname in selentries): |
2347 continue | 2349 continue |
2348 fm.startitem() | 2350 fm.startitem() |
2349 fm.condwrite(ui.debugflag, b'source', b'%s: ', source) | 2351 fm.condwrite(show_source, b'source', b'%s: ', source) |
2350 if uniquesel: | 2352 if uniquesel: |
2351 fm.data(name=entryname) | 2353 fm.data(name=entryname) |
2352 fm.write(b'value', b'%s\n', value) | 2354 fm.write(b'value', b'%s\n', value) |
2353 else: | 2355 else: |
2354 fm.write(b'name value', b'%s=%s\n', entryname, value) | 2356 fm.write(b'name value', b'%s=%s\n', entryname, value) |