Show More
@@ -2267,7 +2267,9 b' def config(ui, repo, *values, **opts):' | |||||
2267 | fm.write(b'value', b'%s\n', value) |
|
2267 | fm.write(b'value', b'%s\n', value) | |
2268 | else: |
|
2268 | else: | |
2269 | fm.write(b'name value', b'%s=%s\n', entryname, value) |
|
2269 | fm.write(b'name value', b'%s=%s\n', entryname, value) | |
|
2270 | if formatter.isprintable(defaultvalue): | |||
2270 | fm.data(defaultvalue=defaultvalue) |
|
2271 | fm.data(defaultvalue=defaultvalue) | |
|
2272 | # TODO: no idea how to process unsupported defaultvalue types | |||
2271 | matched = True |
|
2273 | matched = True | |
2272 | fm.end() |
|
2274 | fm.end() | |
2273 | if matched: |
|
2275 | if matched: |
@@ -136,6 +136,16 b' from .utils import (' | |||||
136 | pickle = util.pickle |
|
136 | pickle = util.pickle | |
137 |
|
137 | |||
138 |
|
138 | |||
|
139 | def isprintable(obj): | |||
|
140 | """Check if the given object can be directly passed in to formatter's | |||
|
141 | write() and data() functions | |||
|
142 | ||||
|
143 | Returns False if the object is unsupported or must be pre-processed by | |||
|
144 | formatdate(), formatdict(), or formatlist(). | |||
|
145 | """ | |||
|
146 | return isinstance(obj, (type(None), bool, int, pycompat.long, float, bytes)) | |||
|
147 | ||||
|
148 | ||||
139 | class _nullconverter(object): |
|
149 | class _nullconverter(object): | |
140 | '''convert non-primitive data types to be processed by formatter''' |
|
150 | '''convert non-primitive data types to be processed by formatter''' | |
141 |
|
151 |
@@ -87,6 +87,170 b' Test case sensitive configuration' | |||||
87 | } |
|
87 | } | |
88 | ] |
|
88 | ] | |
89 |
|
89 | |||
|
90 | Test config default of various types: | |||
|
91 | ||||
|
92 | {"defaultvalue": ""} for -T'json(defaultvalue)' looks weird, but that's | |||
|
93 | how the templater works. Unknown keywords are evaluated to "". | |||
|
94 | ||||
|
95 | dynamicdefault | |||
|
96 | ||||
|
97 | $ hg config --config alias.foo= alias -Tjson | |||
|
98 | [ | |||
|
99 | { | |||
|
100 | "name": "alias.foo", | |||
|
101 | "source": "--config", | |||
|
102 | "value": "" | |||
|
103 | } | |||
|
104 | ] | |||
|
105 | $ hg config --config alias.foo= alias -T'json(defaultvalue)' | |||
|
106 | [ | |||
|
107 | {"defaultvalue": ""} | |||
|
108 | ] | |||
|
109 | $ hg config --config alias.foo= alias -T'{defaultvalue}\n' | |||
|
110 | ||||
|
111 | ||||
|
112 | null | |||
|
113 | ||||
|
114 | $ hg config --config auth.cookiefile= auth -Tjson | |||
|
115 | [ | |||
|
116 | { | |||
|
117 | "defaultvalue": null, | |||
|
118 | "name": "auth.cookiefile", | |||
|
119 | "source": "--config", | |||
|
120 | "value": "" | |||
|
121 | } | |||
|
122 | ] | |||
|
123 | $ hg config --config auth.cookiefile= auth -T'json(defaultvalue)' | |||
|
124 | [ | |||
|
125 | {"defaultvalue": ""} | |||
|
126 | ] | |||
|
127 | $ hg config --config auth.cookiefile= auth -T'{defaultvalue}\n' | |||
|
128 | ||||
|
129 | ||||
|
130 | false | |||
|
131 | ||||
|
132 | $ hg config --config commands.commit.post-status= commands -Tjson | |||
|
133 | [ | |||
|
134 | { | |||
|
135 | "defaultvalue": false, | |||
|
136 | "name": "commands.commit.post-status", | |||
|
137 | "source": "--config", | |||
|
138 | "value": "" | |||
|
139 | } | |||
|
140 | ] | |||
|
141 | $ hg config --config commands.commit.post-status= commands -T'json(defaultvalue)' | |||
|
142 | [ | |||
|
143 | {"defaultvalue": false} | |||
|
144 | ] | |||
|
145 | $ hg config --config commands.commit.post-status= commands -T'{defaultvalue}\n' | |||
|
146 | False | |||
|
147 | ||||
|
148 | true | |||
|
149 | ||||
|
150 | $ hg config --config format.dotencode= format -Tjson | |||
|
151 | [ | |||
|
152 | { | |||
|
153 | "defaultvalue": true, | |||
|
154 | "name": "format.dotencode", | |||
|
155 | "source": "--config", | |||
|
156 | "value": "" | |||
|
157 | } | |||
|
158 | ] | |||
|
159 | $ hg config --config format.dotencode= format -T'json(defaultvalue)' | |||
|
160 | [ | |||
|
161 | {"defaultvalue": true} | |||
|
162 | ] | |||
|
163 | $ hg config --config format.dotencode= format -T'{defaultvalue}\n' | |||
|
164 | True | |||
|
165 | ||||
|
166 | bytes | |||
|
167 | ||||
|
168 | $ hg config --config commands.resolve.mark-check= commands -Tjson | |||
|
169 | [ | |||
|
170 | { | |||
|
171 | "defaultvalue": "none", | |||
|
172 | "name": "commands.resolve.mark-check", | |||
|
173 | "source": "--config", | |||
|
174 | "value": "" | |||
|
175 | } | |||
|
176 | ] | |||
|
177 | $ hg config --config commands.resolve.mark-check= commands -T'json(defaultvalue)' | |||
|
178 | [ | |||
|
179 | {"defaultvalue": "none"} | |||
|
180 | ] | |||
|
181 | $ hg config --config commands.resolve.mark-check= commands -T'{defaultvalue}\n' | |||
|
182 | none | |||
|
183 | ||||
|
184 | empty list | |||
|
185 | ||||
|
186 | $ hg config --config commands.show.aliasprefix= commands -Tjson | |||
|
187 | [ | |||
|
188 | { | |||
|
189 | "name": "commands.show.aliasprefix", | |||
|
190 | "source": "--config", | |||
|
191 | "value": "" | |||
|
192 | } | |||
|
193 | ] | |||
|
194 | $ hg config --config commands.show.aliasprefix= commands -T'json(defaultvalue)' | |||
|
195 | [ | |||
|
196 | {"defaultvalue": ""} | |||
|
197 | ] | |||
|
198 | $ hg config --config commands.show.aliasprefix= commands -T'{defaultvalue}\n' | |||
|
199 | ||||
|
200 | ||||
|
201 | nonempty list | |||
|
202 | ||||
|
203 | $ hg config --config progress.format= progress -Tjson | |||
|
204 | [ | |||
|
205 | { | |||
|
206 | "name": "progress.format", | |||
|
207 | "source": "--config", | |||
|
208 | "value": "" | |||
|
209 | } | |||
|
210 | ] | |||
|
211 | $ hg config --config progress.format= progress -T'json(defaultvalue)' | |||
|
212 | [ | |||
|
213 | {"defaultvalue": ""} | |||
|
214 | ] | |||
|
215 | $ hg config --config progress.format= progress -T'{defaultvalue}\n' | |||
|
216 | ||||
|
217 | ||||
|
218 | int | |||
|
219 | ||||
|
220 | $ hg config --config profiling.freq= profiling -Tjson | |||
|
221 | [ | |||
|
222 | { | |||
|
223 | "defaultvalue": 1000, | |||
|
224 | "name": "profiling.freq", | |||
|
225 | "source": "--config", | |||
|
226 | "value": "" | |||
|
227 | } | |||
|
228 | ] | |||
|
229 | $ hg config --config profiling.freq= profiling -T'json(defaultvalue)' | |||
|
230 | [ | |||
|
231 | {"defaultvalue": 1000} | |||
|
232 | ] | |||
|
233 | $ hg config --config profiling.freq= profiling -T'{defaultvalue}\n' | |||
|
234 | 1000 | |||
|
235 | ||||
|
236 | float | |||
|
237 | ||||
|
238 | $ hg config --config profiling.showmax= profiling -Tjson | |||
|
239 | [ | |||
|
240 | { | |||
|
241 | "defaultvalue": 0.999, | |||
|
242 | "name": "profiling.showmax", | |||
|
243 | "source": "--config", | |||
|
244 | "value": "" | |||
|
245 | } | |||
|
246 | ] | |||
|
247 | $ hg config --config profiling.showmax= profiling -T'json(defaultvalue)' | |||
|
248 | [ | |||
|
249 | {"defaultvalue": 0.999} | |||
|
250 | ] | |||
|
251 | $ hg config --config profiling.showmax= profiling -T'{defaultvalue}\n' | |||
|
252 | 0.999 | |||
|
253 | ||||
90 | Test empty config source: |
|
254 | Test empty config source: | |
91 |
|
255 | |||
92 | $ cat <<EOF > emptysource.py |
|
256 | $ cat <<EOF > emptysource.py |
General Comments 0
You need to be logged in to leave comments.
Login now