[PATCH] formatter: allow json to handle more levels of depth

Yuya Nishihara yuya at tcha.org
Tue Mar 8 10:56:47 EST 2016

On Tue, 8 Mar 2016 15:26:38 +0000, Kostia Balytskyi wrote:
> On 3/8/16, 3:17 PM, "Yuya Nishihara" <youjah at gmail.com on behalf of yuya at tcha.org> wrote:
> >The templater requires a list of dicts, which isn't always necessary in JSON.
> >For example, "log -Tjson" renders "tags" as follows:
> >
> >  "tags": ["tip"],
> >
> >We can't do that with the current formatter API. To make it compatible with
> >the template functions, we would have to render it as follows:
> >
> >  "tags": [{"tag": "tip"}]
> >
> >This is IMO ugly.
> I agree, this is ugly. Technically, the change that I'm proposing can output
> ``"tags": ["tip"]`` as well if you do ``fm.data(tags=["tip"])``. Bigger
> problem would be to actually use in a templated output produced by formatter.

Yep. Can you give me some time to consider this? I don't have enough time
to hack on hg on weekdays.

> >> "JSON output should be stable".
> >
> >It would be a big BC to change the structure of JSON output. I know it's okay
> >for "evolve --list" since it is experimental, but this patch isn't specific to
> >evolve.
> I don't get how this change is breaking. All the existing behavior stays
> the same, one-level json gets printed by formatter in the same way
> (at least this was my goal).

I meant multi-level data could be used by another command, and it could render
unfortunate JSON and force us to tackle on the compatibility hell.

More information about the Mercurial-devel mailing list