[PATCH] formatter: make grep command use formatter

Kostia Balytskyi ikostia at fb.com
Wed Mar 9 10:16:23 EST 2016


On 3/9/16, 12:19 AM, "Matt Mackall" <mpm at selenic.com> wrote:


>On Tue, 2016-03-08 at 18:34 -0500, timeless wrote:
>> So... I love the idea. Problems:
>> 
>> 1. this breaks color.
>
>I'd consider this blocking.
>
>> 2. reviewing the generictemplating plan [1]
>
>But I wouldn't consider this blocking.
>
>> +    tmpl = ["{label('grep.filename', filename)}", "{label('grep.rev', rev)}"]
>> +    if opts.get('line_number'):
>> +        tmpl.append("{label('grep.linenumber', linenum)}")
>
>You're making this too complicated.
>
>The formatter is designed to replace plain old ui.write() from a programmer's
>perspective, to keep code simple. If you're doing significant rewriting to go
>from the ui.write() model to the formatter, something is very wrong.
>
>So don't build a template, just make some linear calls:
>
>  fm.startitem()
>  fm.write("user", "user: %s", user, label="foo.user")
>  fm.condwrite(showrev, "rev", " rev: %d", rev, label="foo.rev")
>  fm.plain("\n")
>
>When no -T is provided, this falls through to the aforementioned plain ui.write(), and thus ends up much faster than the templater.
Hm. What do I do when I have a list, like bookmarks? I could implement something like ``fm.writelist("bookmarks", bookmarks)`` I guess, but I'm not sure
whether it's the right approach/desired.

>
>-- 
>Mathematics is the supreme nostalgia of our time.
>


More information about the Mercurial-devel mailing list