[PATCH v2] formatter: fixing bug that prevented labels from working

Yuya Nishihara yuya at tcha.org
Sat Mar 5 08:46:18 EST 2016


On Fri, 4 Mar 2016 02:42:49 -0800, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia at fb.com>
> # Date 1457087941 28800
> #      Fri Mar 04 02:39:01 2016 -0800
> # Node ID 4fe6e433f58e2a358c083e09e2e90735b289f01c
> # Parent  4f7a5e4f2daff0a65aa470d9f70365ad55aaa100
> formatter: fixing bug that prevented labels from working
> 
> 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 --git a/hgext/color.py b/hgext/color.py
> --- a/hgext/color.py
> +++ b/hgext/color.py
> @@ -491,9 +491,13 @@ def templatelabel(context, mapping, args
>  
>      thing = args[1][0](context, mapping, args[1][1])
>  
> +    ui = mapping.get('__ui')
>      # apparently, repo could be a string that is the favicon?
>      repo = mapping.get('repo', '')
> -    if isinstance(repo, str):
> +    if not ui and not isinstance(repo, str):
> +        ui = repo.ui
> +
> +    if ui is None:
>          return thing

(FYI: I'm going to send patches that will move this function to templater)

It seems awkward that label() looks for a ui object by several names and falls
back to do nothing. Can "ui" be a mandatory parameter? Both templateformatter
and changeset_templater can pass "ui" to templater.

Regarding the name, I think mapping['ui'] is okay. At some point, we should
split the mapping dict to public keywords and internal resources, but that
will require lots of work. Until then, 'ui' sounds good as we have 'ctx' and
'repo'.

> --- a/mercurial/formatter.py
> +++ b/mercurial/formatter.py
> @@ -152,8 +152,9 @@ class templateformatter(baseformatter):
>          baseformatter.__init__(self, ui, topic, opts)
>          self._topic = topic
>          self._t = gettemplater(ui, topic, opts.get('template', ''))
> +        self.ui = ui

It has self._ui.


More information about the Mercurial-devel mailing list