122 elif t == b'items': |
124 elif t == b'items': |
123 # Don't print anything for 'items'. |
125 # Don't print anything for 'items'. |
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 |