diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1502,6 +1502,7 @@ class changeset_templater(changeset_prin props['templ'] = self.t props['ctx'] = ctx props['repo'] = self.repo + props['ui'] = self.repo.ui props['revcache'] = {'copies': copies} props['cache'] = self.cache diff --git a/mercurial/formatter.py b/mercurial/formatter.py --- a/mercurial/formatter.py +++ b/mercurial/formatter.py @@ -153,7 +153,7 @@ class templateformatter(baseformatter): self._topic = topic self._t = gettemplater(ui, topic, opts.get('template', '')) def _showitem(self): - g = self._t(self._topic, **self._item) + g = self._t(self._topic, ui=self._ui, **self._item) self._ui.write(templater.stringify(g)) def lookuptemplate(ui, topic, tmpl): diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -549,16 +549,15 @@ def label(context, mapping, args): thing = evalstring(context, mapping, args[1]) - # apparently, repo could be a string that is the favicon? - repo = mapping.get('repo', '') - if isinstance(repo, str): + ui = mapping.get('ui', '') + if isinstance(ui, 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) + return ui.label(thing, label) def latesttag(context, mapping, args): """:latesttag([pattern]): The global tags matching the given pattern on the diff --git a/tests/test-status-color.t b/tests/test-status-color.t --- a/tests/test-status-color.t +++ b/tests/test-status-color.t @@ -30,6 +30,15 @@ hg status in repo root: [status.unknown|? ][status.unknown|b/in_b] [status.unknown|? ][status.unknown|in_root] +hg status with template + $ hg status -T "{label('red', path)}\n" --color=debug + [red|a/1/in_a_1] + [red|a/in_a] + [red|b/1/in_b_1] + [red|b/2/in_b_2] + [red|b/in_b] + [red|in_root] + hg status . in repo root: $ hg status --color=always .