Show More
@@ -485,10 +485,6 b' def templatelabel(context, mapping, args' | |||
|
485 | 485 | # i18n: "label" is a keyword |
|
486 | 486 | raise error.ParseError(_("label expects two arguments")) |
|
487 | 487 | |
|
488 | # add known effects to the mapping so symbols like 'red', 'bold', | |
|
489 | # etc. don't need to be quoted | |
|
490 | mapping.update(dict([(k, k) for k in _effects])) | |
|
491 | ||
|
492 | 488 | thing = templater.evalstring(context, mapping, args[1]) |
|
493 | 489 | |
|
494 | 490 | # apparently, repo could be a string that is the favicon? |
@@ -496,7 +492,9 b' def templatelabel(context, mapping, args' | |||
|
496 | 492 | if isinstance(repo, str): |
|
497 | 493 | return thing |
|
498 | 494 | |
|
499 | label = templater.evalstring(context, mapping, args[0]) | |
|
495 | # preserve unknown symbol as literal so effects like 'red', 'bold', | |
|
496 | # etc. don't need to be quoted | |
|
497 | label = templater.evalstringliteral(context, mapping, args[0]) | |
|
500 | 498 | |
|
501 | 499 | return repo.ui.label(thing, label) |
|
502 | 500 |
@@ -231,6 +231,16 b' def evalstring(context, mapping, arg):' | |||
|
231 | 231 | func, data = arg |
|
232 | 232 | return stringify(func(context, mapping, data)) |
|
233 | 233 | |
|
234 | def evalstringliteral(context, mapping, arg): | |
|
235 | """Evaluate given argument as string template, but returns symbol name | |
|
236 | if it is unknown""" | |
|
237 | func, data = arg | |
|
238 | if func is runsymbol: | |
|
239 | thing = func(context, mapping, data, default=data) | |
|
240 | else: | |
|
241 | thing = func(context, mapping, data) | |
|
242 | return stringify(thing) | |
|
243 | ||
|
234 | 244 | def runinteger(context, mapping, data): |
|
235 | 245 | return int(data) |
|
236 | 246 | |
@@ -245,7 +255,7 b' def _recursivesymbolblocker(key):' | |||
|
245 | 255 | def _runrecursivesymbol(context, mapping, key): |
|
246 | 256 | raise error.Abort(_("recursive reference '%s' in template") % key) |
|
247 | 257 | |
|
248 | def runsymbol(context, mapping, key): | |
|
258 | def runsymbol(context, mapping, key, default=''): | |
|
249 | 259 | v = mapping.get(key) |
|
250 | 260 | if v is None: |
|
251 | 261 | v = context._defaults.get(key) |
@@ -257,7 +267,7 b' def runsymbol(context, mapping, key):' | |||
|
257 | 267 | try: |
|
258 | 268 | v = context.process(key, safemapping) |
|
259 | 269 | except TemplateNotFound: |
|
260 |
v = |
|
|
270 | v = default | |
|
261 | 271 | if callable(v): |
|
262 | 272 | return v(**mapping) |
|
263 | 273 | return v |
@@ -3178,6 +3178,11 b' Test recursive evaluation:' | |||
|
3178 | 3178 | $ hg log --color=always -l 1 --template '{label("text.{rev}", "text\n")}' |
|
3179 | 3179 | \x1b[0;32mtext\x1b[0m (esc) |
|
3180 | 3180 | |
|
3181 | color effect can be specified without quoting: | |
|
3182 | ||
|
3183 | $ hg log --color=always -l 1 --template '{label(red, "text\n")}' | |
|
3184 | \x1b[0;31mtext\x1b[0m (esc) | |
|
3185 | ||
|
3181 | 3186 | Test branches inside if statement: |
|
3182 | 3187 | |
|
3183 | 3188 | $ hg log -r 0 --template '{if(branches, "yes", "no")}\n' |
General Comments 0
You need to be logged in to leave comments.
Login now