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

Kostia Balytskyi ikostia at fb.com
Mon Mar 7 10:55:08 EST 2016


On 3/7/16, 3:49 PM, "Yuya Nishihara" <youjah at gmail.com on behalf of yuya at tcha.org> wrote:


>On Sun, 6 Mar 2016 23:06:49 +0000, Kostia Balytskyi wrote:
>> On 3/6/16, 4:16 PM, "Yuya Nishihara" <youjah at gmail.com on behalf of yuya at tcha.org> wrote:
>> >On Fri, 4 Mar 2016 16:29:26 +0000, Kostia Balytskyi wrote:
>> >> This is a sample output of `evolve --list` with below fix applied to mercurial:
>> >> 
>> >> ```
>> >> ikostia at dev1902.lla1:~/temprepos/supertroubledrepo$ HGRCPATH= ~/clowncopter/hg evolve --list  --config extensions.lz4revlog= --config extensions.color= --config extensions.evolve=~/evolve/hgext/evolve.py
>> >> [
>> >> ...
>> >>   {
>> >>     "desc": "e (e+f split)",
>> >>     "divergentsets": [{"divergentwith": [{"node": "01a3e66ba0301a4cbb7d519f8b9980af271241bd"}],"gcea": "3efa43a7427b9b19dc715853251d4891d3e9334c"}, {"divergentwith": [{"node": "add9a356b8cfca95c588f51f05291ad97ffbaea8"}],"gcea": "3efa43a7427b9b19dc715853251d4891d3e9334c"}],
>> >>     "node": "84e1c6ae319d139241a02ef5e939d7494b9b11d7",
>> >>     "unstableparents": [{"unstableparent": "1995fc658ad6db877b932a45deb411980ccc064e"}]
>> >>   },
>> >
>> >Looks like you've designed the data structure to be processed by the templater.
>> >Isn't that verbose as a JSON output?
>> >
>> >For example, "unstableparents" could be a list of node ids in JSON:
>> >
>> >  "unstableparents": ["1995fc658ad6db877b932a45deb411980ccc064e"]
>> >
>> >but templater requires a key:
>> >
>> >  "unstableparents": [{"unstableparent": "1995fc658ad6db877b932a45deb411980ccc064e"}]
>> >
>> >moreover it would need a ctx object for full templating:
>> >
>> >  {unstableparents % "{rev}:{node|short} {desc|firstline}"}
>> >   ~~~~~~~~~~~~~~~
>> >     yields {'ctx': ctx}
>> >
>> >I don't have any idea right now, but nested data structure wouldn't be handled
>> >well by the current formatter API.
>> 
>> I guess it depends on whether you want to be able to have all the 'rev', 'node', 'desc' and stuff to be there. If you're fine with having a limited output where you only have access not to all the ``ctx`` fields, but just some predefined set of them, my approach should be good enough.
>
>Hmm, but we provide -T option because people are likely to have their own needs.
>They'll expect {rev}, {branch}, etc. can be used if "evolve -l" looks like a
>log command.
>
>That said, I think it's okay to start from a limited version. My main concern
>is that a nested data structure looks ugly in JSON if it has to be compatible
>with the templater. And JSON output should be stable. (timeless is working on
>it.)

Well, if people expect ``rev``, ``node``, ``desc``, I can just provide those to a reasonable amount. And "nothing in evolution is stable" seems to be an argument for getting working versions out there without much fear for backwards compatibility-related problems.

Another thing: we're currently discussing ``evolve --list`` rather than multi-level JSON output. What harm does the latter do?

Also, I don't get what you mean by "nested data structure looks ugly in JSON if it has to be compatible with templater" and "JSON output should be stable". Could you please explain a bit more?


More information about the Mercurial-devel mailing list