# HG changeset patch # User Kostia Balytskyi # Date 1457438913 28800 # Node ID 3356bf61fa2598558259a2320625277d0ace8393 # Parent e13e0e1899900019427587fa972f02caf1ba98d2 formatter: make labels work with templated output To describe the bug this fix is addressing, one can do ``$ hg status -T "{label('red', path)}\n" --color=debug`` and observe that the label is not applied before my fix and applied with it. diff -r e13e0e189990 -r 3356bf61fa25 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Tue Mar 08 14:32:03 2016 +0000 +++ b/mercurial/cmdutil.py Tue Mar 08 04:08:33 2016 -0800 @@ -1502,6 +1502,7 @@ 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 -r e13e0e189990 -r 3356bf61fa25 mercurial/formatter.py --- a/mercurial/formatter.py Tue Mar 08 14:32:03 2016 +0000 +++ b/mercurial/formatter.py Tue Mar 08 04:08:33 2016 -0800 @@ -153,7 +153,7 @@ 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 -r e13e0e189990 -r 3356bf61fa25 mercurial/templater.py --- a/mercurial/templater.py Tue Mar 08 14:32:03 2016 +0000 +++ b/mercurial/templater.py Tue Mar 08 04:08:33 2016 -0800 @@ -549,16 +549,15 @@ 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 -r e13e0e189990 -r 3356bf61fa25 tests/test-status-color.t --- a/tests/test-status-color.t Tue Mar 08 14:32:03 2016 +0000 +++ b/tests/test-status-color.t Tue Mar 08 04:08:33 2016 -0800 @@ -30,6 +30,15 @@ [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 .