[PATCH] formatter: make grep command use formatter

Kostia Balytskyi ikostia at fb.com
Wed Mar 9 14:46:50 EST 2016






On 3/9/16, 3:16 PM, "Mercurial-devel on behalf of Kostia Balytskyi" <mercurial-devel-bounces at mercurial-scm.org on behalf of ikostia at fb.com> wrote:

>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.

I just noticed the ``deftext`` parameter. I presume it's what handles lists.

>
>
>
>>
>
>>-- 
>
>>Mathematics is the supreme nostalgia of our time.
>
>>
>
>_______________________________________________
>Mercurial-devel mailing list
>Mercurial-devel at mercurial-scm.org
>https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=cAbzqh511IQVuiP35syTSkjg-v2ts6oCWZeMol_ZXdw&s=qkBtaCYcICF5klodroPRGHIj2dlw_BD1ePmUJUyHoSM&e= 


More information about the Mercurial-devel mailing list