[PATCH] formatter: fixing bug that prevented labels from working
Kostia Balytskyi
ikostia at fb.com
Fri Mar 4 05:20:25 EST 2016
On 3/3/16, 4:40 PM, "Yuya Nishihara" <youjah at gmail.com on behalf of yuya at tcha.org> wrote:
>On Thu, 3 Mar 2016 08:27:57 -0800, Kostia Balytskyi wrote:
>> # HG changeset patch
>> # User Kostia Balytskyi <ikostia at fb.com>
>> # Date 1457022116 28800
>> # Thu Mar 03 08:21:56 2016 -0800
>> # Node ID 09dd1768aafb67bc4c342fb5317b18c085231b7e
>> # 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.
>
>> class templater(object):
>>
>> def __init__(self, mapfile, filters=None, defaults=None, cache=None,
>> - minchunk=1024, maxchunk=65536):
>> + minchunk=1024, maxchunk=65536, ui=None):
>> '''set up template engine.
>> mapfile is name of file to read map definitions from.
>> filters is dict of functions. each transforms a value into another.
>> @@ -886,6 +886,7 @@ class templater(object):
>> self.defaults = defaults
>> self.minchunk, self.maxchunk = minchunk, maxchunk
>> self.ecache = {}
>> + self.ui = ui
>
>Ugh, I know several template functions never work in formatter, but keeping ui
>by templater seems somewhat wrong. I'll take a look more deeply later.
Instead of templater keeping it, we can pass it as one of the arguments to ``__call__``:
```
class templateformatter(baseformatter):
def __init__(self, ui, topic, opts):
baseformatter.__init__(self, ui, topic, opts)
self._topic = topic
self.ui = ui
self._t = gettemplater(topic, opts.get('template', ''))
def _showitem(self):
g = self._t(self._topic, __ui=self.ui, **self._item)
self._ui.write(templater.stringify(g))
```
This will be automatically picked up by the current implementation. Although I'm not sure how this approach is better. I'll send a v2, let me know what you think.
More information about the Mercurial-devel
mailing list