Mercurial > hg
changeset 28374:af3bd9d1dbc1
templater: move label() function from color extension
ui.label() is no-op by default, so we can just call ui.label() by label()
template function no matter if the color is enabled or not.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 11 Jun 2015 23:04:14 +0900 |
parents | 9a9dd71e882c |
children | 97cb1aeaca78 |
files | hgext/color.py mercurial/templater.py tests/test-command-template.t |
diffstat | 3 files changed, 19 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/color.py Thu Jun 11 22:58:27 2015 +0900 +++ b/hgext/color.py Thu Jun 11 23:04:14 2015 +0900 @@ -157,7 +157,6 @@ from mercurial import cmdutil, commands, dispatch, extensions, subrepo, util from mercurial import ui as uimod -from mercurial import templater, error from mercurial.i18n import _ cmdtable = {} @@ -480,24 +479,6 @@ for s in msg.split('\n')]) return msg -def templatelabel(context, mapping, args): - if len(args) != 2: - # i18n: "label" is a keyword - raise error.ParseError(_("label expects two arguments")) - - thing = templater.evalstring(context, mapping, args[1]) - - # apparently, repo could be a string that is the favicon? - repo = mapping.get('repo', '') - if isinstance(repo, str): - return thing - - # preserve unknown symbol as literal so effects like 'red', 'bold', - # etc. don't need to be quoted - label = templater.evalstringliteral(context, mapping, args[0]) - - return repo.ui.label(thing, label) - def uisetup(ui): if ui.plain(): return @@ -519,8 +500,6 @@ return orig(gitsub, commands, env, stream, cwd) extensions.wrapfunction(dispatch, '_runcommand', colorcmd) extensions.wrapfunction(subrepo.gitsubrepo, '_gitnodir', colorgit) - templatelabel.__doc__ = templater.funcs['label'].__doc__ - templater.funcs['label'] = templatelabel def extsetup(ui): commands.globalopts.append(
--- a/mercurial/templater.py Thu Jun 11 22:58:27 2015 +0900 +++ b/mercurial/templater.py Thu Jun 11 23:04:14 2015 +0900 @@ -547,8 +547,18 @@ # i18n: "label" is a keyword raise error.ParseError(_("label expects two arguments")) - # ignore args[0] (the label string) since this is supposed to be a a no-op - yield args[1][0](context, mapping, args[1][1]) + thing = evalstring(context, mapping, args[1]) + + # apparently, repo could be a string that is the favicon? + repo = mapping.get('repo', '') + if isinstance(repo, str): + return thing + + # preserve unknown symbol as literal so effects like 'red', 'bold', + # etc. don't need to be quoted + label = evalstringliteral(context, mapping, args[0]) + + return repo.ui.label(thing, label) def latesttag(context, mapping, args): """:latesttag([pattern]): The global tags matching the given pattern on the
--- a/tests/test-command-template.t Thu Jun 11 22:58:27 2015 +0900 +++ b/tests/test-command-template.t Thu Jun 11 23:04:14 2015 +0900 @@ -3183,6 +3183,13 @@ $ hg log --color=always -l 1 --template '{label(red, "text\n")}' \x1b[0;31mtext\x1b[0m (esc) +label should be no-op if color is disabled: + + $ hg log --color=never -l 1 --template '{label(red, "text\n")}' + text + $ hg log --config extensions.color=! -l 1 --template '{label(red, "text\n")}' + text + Test branches inside if statement: $ hg log -r 0 --template '{if(branches, "yes", "no")}\n'