[PATCH 1 of 2 V2] formatter: reserve _ prefixed keys as internal and don't render
Yuya Nishihara
yuya at tcha.org
Sat Apr 1 15:08:05 UTC 2017
On Wed, 22 Mar 2017 16:21:34 +0000, Ryan McElroy wrote:
> This seems like a good time to bring up by long-held desire for a JSON
> template that allows specifying what keys you're interested in. This
> would solve this problem more suitably than internal name-munging.
>
> To expand, -T json is insufficient for some things, like requesting file
> adds from hg log, which might be slow to ask for in large repos. I'd
> like a syntax like:
>
> -T json(desc,fileadds)
Suppose template keywords can be lazily evaluated, this will be doable by
templater.
1. add jsonobj(*keywords) function that evaluates each keyword and dump
them as JSON object:
jsonobj(desc, fileadds)
=> '{"desc": desc, "fileadds": fileadds}'
2. add :docheader, :docfooter, and :separator options
[templates]
json = "{jsonobj(desc, fileadds)}"
json:docheader = "[\n"
json:docfooter = "]\n"
json:separator = ",\n"
3. add function-like template specifier
[templates]
json(*args) = "{jsonobj(*args)}"
4. make json(*args) a builtin template
Perhaps (3) isn't easy, but we can just hard-code parsing of "json(...)",
and implement the general form later.
More information about the Mercurial-devel
mailing list