[PATCH] formatter: make grep command use formatter

Matt Mackall mpm at selenic.com
Tue Mar 8 19:19:08 EST 2016


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.

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list