Show More
@@ -2372,47 +2372,16 def config(ui, repo, *values, **opts): | |||||
2372 |
|
2372 | |||
2373 | ui.pager(b'config') |
|
2373 | ui.pager(b'config') | |
2374 | config_command.show_component(ui, repo) |
|
2374 | config_command.show_component(ui, repo) | |
2375 | fm = ui.formatter(b'config', pycompat.byteskwargs(opts)) |
|
2375 | ||
2376 | untrusted = bool(opts.get('untrusted')) |
|
2376 | matched = config_command.show_config( | |
2377 |
|
2377 | ui, | ||
2378 | selsections = selentries = [] |
|
2378 | repo, | |
2379 | if values: |
|
2379 | value_filters=values, | |
2380 | selsections = [v for v in values if b'.' not in v] |
|
2380 | formatter_options=pycompat.byteskwargs(opts), | |
2381 | selentries = [v for v in values if b'.' in v] |
|
2381 | untrusted=bool(opts.get('untrusted')), | |
2382 | uniquesel = len(selentries) == 1 and not selsections |
|
2382 | all_known=bool(opts.get('exp_all_known')), | |
2383 | selsections = set(selsections) |
|
2383 | show_source=bool(ui.debugflag or opts.get('source')), | |
2384 | selentries = set(selentries) |
|
2384 | ) | |
2385 |
|
||||
2386 | matched = False |
|
|||
2387 | all_known = opts['exp_all_known'] |
|
|||
2388 | show_source = ui.debugflag or opts.get('source') |
|
|||
2389 | entries = ui.walkconfig(untrusted=untrusted, all_known=all_known) |
|
|||
2390 | for section, name, value in entries: |
|
|||
2391 | source = ui.configsource(section, name, untrusted) |
|
|||
2392 | value = pycompat.bytestr(value) |
|
|||
2393 | defaultvalue = ui.configdefault(section, name) |
|
|||
2394 | if fm.isplain(): |
|
|||
2395 | source = source or b'none' |
|
|||
2396 | value = value.replace(b'\n', b'\\n') |
|
|||
2397 | entryname = section + b'.' + name |
|
|||
2398 | if values and not (section in selsections or entryname in selentries): |
|
|||
2399 | continue |
|
|||
2400 | fm.startitem() |
|
|||
2401 | fm.condwrite(show_source, b'source', b'%s: ', source) |
|
|||
2402 | if uniquesel: |
|
|||
2403 | fm.data(name=entryname) |
|
|||
2404 | fm.write(b'value', b'%s\n', value) |
|
|||
2405 | else: |
|
|||
2406 | fm.write(b'name value', b'%s=%s\n', entryname, value) |
|
|||
2407 | if formatter.isprintable(defaultvalue): |
|
|||
2408 | fm.data(defaultvalue=defaultvalue) |
|
|||
2409 | elif isinstance(defaultvalue, list) and all( |
|
|||
2410 | formatter.isprintable(e) for e in defaultvalue |
|
|||
2411 | ): |
|
|||
2412 | fm.data(defaultvalue=fm.formatlist(defaultvalue, name=b'value')) |
|
|||
2413 | # TODO: no idea how to process unsupported defaultvalue types |
|
|||
2414 | matched = True |
|
|||
2415 | fm.end() |
|
|||
2416 | if matched: |
|
2385 | if matched: | |
2417 | return 0 |
|
2386 | return 0 | |
2418 | return 1 |
|
2387 | return 1 |
@@ -4,13 +4,15 from __future__ import annotations | |||||
4 |
|
4 | |||
5 | import os |
|
5 | import os | |
6 |
|
6 | |||
7 | from typing import Any, Dict, Optional |
|
7 | from typing import Any, Collection, Dict, Optional | |
8 |
|
8 | |||
9 | from ..i18n import _ |
|
9 | from ..i18n import _ | |
10 |
|
10 | |||
11 | from .. import ( |
|
11 | from .. import ( | |
12 | cmdutil, |
|
12 | cmdutil, | |
13 | error, |
|
13 | error, | |
|
14 | formatter, | |||
|
15 | pycompat, | |||
14 | requirements, |
|
16 | requirements, | |
15 | ui as uimod, |
|
17 | ui as uimod, | |
16 | util, |
|
18 | util, | |
@@ -124,3 +126,76 def show_component(ui: uimod.ui, repo) - | |||||
124 | pass |
|
126 | pass | |
125 | else: |
|
127 | else: | |
126 | raise error.ProgrammingError(b'unknown rctype: %s' % t) |
|
128 | raise error.ProgrammingError(b'unknown rctype: %s' % t) | |
|
129 | ||||
|
130 | ||||
|
131 | def show_config( | |||
|
132 | ui: uimod.ui, | |||
|
133 | repo, | |||
|
134 | value_filters: Collection[bytes], | |||
|
135 | formatter_options: dict, | |||
|
136 | untrusted: bool = False, | |||
|
137 | all_known: bool = False, | |||
|
138 | show_source: bool = False, | |||
|
139 | ) -> bool: | |||
|
140 | """Display config value to the user | |||
|
141 | ||||
|
142 | The display is done using a dedicated `formatter` object. | |||
|
143 | ||||
|
144 | ||||
|
145 | :value_filters: | |||
|
146 | if non-empty filter the display value according to these filters. If | |||
|
147 | the filter does not match any value, the function return False. True | |||
|
148 | otherwise. | |||
|
149 | ||||
|
150 | :formatter_option: | |||
|
151 | options passed to the formatter | |||
|
152 | ||||
|
153 | :untrusted: | |||
|
154 | When set, use untrusted value instead of ignoring them | |||
|
155 | ||||
|
156 | :all_known: | |||
|
157 | Display all known config item, not just the one with an explicit value. | |||
|
158 | ||||
|
159 | :show_source: | |||
|
160 | Show where each value has been defined. | |||
|
161 | """ | |||
|
162 | fm = ui.formatter(b'config', formatter_options) | |||
|
163 | selsections = selentries = [] | |||
|
164 | filtered = False | |||
|
165 | if value_filters: | |||
|
166 | selsections = [v for v in value_filters if b'.' not in v] | |||
|
167 | selentries = [v for v in value_filters if b'.' in v] | |||
|
168 | filtered = True | |||
|
169 | uniquesel = len(selentries) == 1 and not selsections | |||
|
170 | selsections = set(selsections) | |||
|
171 | selentries = set(selentries) | |||
|
172 | ||||
|
173 | matched = False | |||
|
174 | entries = ui.walkconfig(untrusted=untrusted, all_known=all_known) | |||
|
175 | for section, name, value in entries: | |||
|
176 | source = ui.configsource(section, name, untrusted) | |||
|
177 | value = pycompat.bytestr(value) | |||
|
178 | defaultvalue = ui.configdefault(section, name) | |||
|
179 | if fm.isplain(): | |||
|
180 | source = source or b'none' | |||
|
181 | value = value.replace(b'\n', b'\\n') | |||
|
182 | entryname = section + b'.' + name | |||
|
183 | if filtered and not (section in selsections or entryname in selentries): | |||
|
184 | continue | |||
|
185 | fm.startitem() | |||
|
186 | fm.condwrite(show_source, b'source', b'%s: ', source) | |||
|
187 | if uniquesel: | |||
|
188 | fm.data(name=entryname) | |||
|
189 | fm.write(b'value', b'%s\n', value) | |||
|
190 | else: | |||
|
191 | fm.write(b'name value', b'%s=%s\n', entryname, value) | |||
|
192 | if formatter.isprintable(defaultvalue): | |||
|
193 | fm.data(defaultvalue=defaultvalue) | |||
|
194 | elif isinstance(defaultvalue, list) and all( | |||
|
195 | formatter.isprintable(e) for e in defaultvalue | |||
|
196 | ): | |||
|
197 | fm.data(defaultvalue=fm.formatlist(defaultvalue, name=b'value')) | |||
|
198 | # TODO: no idea how to process unsupported defaultvalue types | |||
|
199 | matched = True | |||
|
200 | fm.end() | |||
|
201 | return matched |
General Comments 0
You need to be logged in to leave comments.
Login now