Show More
@@ -157,7 +157,6 b' import os' | |||||
157 |
|
157 | |||
158 | from mercurial import cmdutil, commands, dispatch, extensions, subrepo, util |
|
158 | from mercurial import cmdutil, commands, dispatch, extensions, subrepo, util | |
159 | from mercurial import ui as uimod |
|
159 | from mercurial import ui as uimod | |
160 | from mercurial import templater, error |
|
|||
161 | from mercurial.i18n import _ |
|
160 | from mercurial.i18n import _ | |
162 |
|
161 | |||
163 | cmdtable = {} |
|
162 | cmdtable = {} | |
@@ -480,24 +479,6 b' class colorui(uimod.ui):' | |||||
480 | for s in msg.split('\n')]) |
|
479 | for s in msg.split('\n')]) | |
481 | return msg |
|
480 | return msg | |
482 |
|
481 | |||
483 | def templatelabel(context, mapping, args): |
|
|||
484 | if len(args) != 2: |
|
|||
485 | # i18n: "label" is a keyword |
|
|||
486 | raise error.ParseError(_("label expects two arguments")) |
|
|||
487 |
|
||||
488 | thing = templater.evalstring(context, mapping, args[1]) |
|
|||
489 |
|
||||
490 | # apparently, repo could be a string that is the favicon? |
|
|||
491 | repo = mapping.get('repo', '') |
|
|||
492 | if isinstance(repo, str): |
|
|||
493 | return thing |
|
|||
494 |
|
||||
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]) |
|
|||
498 |
|
||||
499 | return repo.ui.label(thing, label) |
|
|||
500 |
|
||||
501 | def uisetup(ui): |
|
482 | def uisetup(ui): | |
502 | if ui.plain(): |
|
483 | if ui.plain(): | |
503 | return |
|
484 | return | |
@@ -519,8 +500,6 b' def uisetup(ui):' | |||||
519 | return orig(gitsub, commands, env, stream, cwd) |
|
500 | return orig(gitsub, commands, env, stream, cwd) | |
520 | extensions.wrapfunction(dispatch, '_runcommand', colorcmd) |
|
501 | extensions.wrapfunction(dispatch, '_runcommand', colorcmd) | |
521 | extensions.wrapfunction(subrepo.gitsubrepo, '_gitnodir', colorgit) |
|
502 | extensions.wrapfunction(subrepo.gitsubrepo, '_gitnodir', colorgit) | |
522 | templatelabel.__doc__ = templater.funcs['label'].__doc__ |
|
|||
523 | templater.funcs['label'] = templatelabel |
|
|||
524 |
|
503 | |||
525 | def extsetup(ui): |
|
504 | def extsetup(ui): | |
526 | commands.globalopts.append( |
|
505 | commands.globalopts.append( |
@@ -547,8 +547,18 b' def label(context, mapping, args):' | |||||
547 | # i18n: "label" is a keyword |
|
547 | # i18n: "label" is a keyword | |
548 | raise error.ParseError(_("label expects two arguments")) |
|
548 | raise error.ParseError(_("label expects two arguments")) | |
549 |
|
549 | |||
550 | # ignore args[0] (the label string) since this is supposed to be a a no-op |
|
550 | thing = evalstring(context, mapping, args[1]) | |
551 | yield args[1][0](context, mapping, args[1][1]) |
|
551 | ||
|
552 | # apparently, repo could be a string that is the favicon? | |||
|
553 | repo = mapping.get('repo', '') | |||
|
554 | if isinstance(repo, str): | |||
|
555 | return thing | |||
|
556 | ||||
|
557 | # preserve unknown symbol as literal so effects like 'red', 'bold', | |||
|
558 | # etc. don't need to be quoted | |||
|
559 | label = evalstringliteral(context, mapping, args[0]) | |||
|
560 | ||||
|
561 | return repo.ui.label(thing, label) | |||
552 |
|
562 | |||
553 | def latesttag(context, mapping, args): |
|
563 | def latesttag(context, mapping, args): | |
554 | """:latesttag([pattern]): The global tags matching the given pattern on the |
|
564 | """:latesttag([pattern]): The global tags matching the given pattern on the |
@@ -3183,6 +3183,13 b' color effect can be specified without qu' | |||||
3183 | $ hg log --color=always -l 1 --template '{label(red, "text\n")}' |
|
3183 | $ hg log --color=always -l 1 --template '{label(red, "text\n")}' | |
3184 | \x1b[0;31mtext\x1b[0m (esc) |
|
3184 | \x1b[0;31mtext\x1b[0m (esc) | |
3185 |
|
3185 | |||
|
3186 | label should be no-op if color is disabled: | |||
|
3187 | ||||
|
3188 | $ hg log --color=never -l 1 --template '{label(red, "text\n")}' | |||
|
3189 | text | |||
|
3190 | $ hg log --config extensions.color=! -l 1 --template '{label(red, "text\n")}' | |||
|
3191 | text | |||
|
3192 | ||||
3186 |
|
|
3193 | Test branches inside if statement: | |
3187 |
|
3194 | |||
3188 |
|
|
3195 | $ hg log -r 0 --template '{if(branches, "yes", "no")}\n' |
General Comments 0
You need to be logged in to leave comments.
Login now