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

Yuya Nishihara yuya at tcha.org
Sun Mar 6 11:16:22 EST 2016


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.


More information about the Mercurial-devel mailing list