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

Kostia Balytskyi ikostia at fb.com
Sun Mar 6 18:06:49 EST 2016


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. This is the current formatter template used for default ``evolve --list`` output (not terribly readable, but describes the point):

```
troublelisttemplate = "{short(node)}: {desc}\n"\
    "{if(unstableparents, '  unstable because of unstable parent(s) "\
    "{unstableparents % \'{short(unstableparent)} \'}\n')}"\
    "{if(obsoleteparents, '  unstable because of obsolete parent(s) "\
    "{obsoleteparents % \'{short(obsoleteparent)} \'}\n')}"\
    "{if(immutableprecursors, '  bumped because of immmutable precursor(s) "\
    "{immutableprecursors % \'{short(immutableprecursor)} \'}\n')}"\
    "{if(divergentsets, '  divergent with:\n{divergentsets % \'    "\
    "({divergentwith % \\'{short(node)} \\' })" \
    "; common evolution ancestor: {short(gcea)}\n\'}')}"


```


And here's a sample output produced with this template, fwiw:
```
ikostia at dev1902.lla1:~/temprepos/supertroubledrepo$ hg evolve --list
  01a3e66ba030: e (amended)
    unstable because of unstable parent(s) 1995fc658ad6
    divergent with:
       (84e1c6ae319d d3b90e9c84ab ); common evolution ancestor: 3efa43a7427b
       (add9a356b8cf ); common evolution ancestor: 3efa43a7427b
  add9a356b8cf: e (rebased)
    divergent with:
      (84e1c6ae319d d3b90e9c84ab ); common evolution ancestor: 3efa43a7427b
      (01a3e66ba030 ); common evolution ancestor: 3efa43a7427b
  84e1c6ae319d: e (e+f split)
    unstable because of unstable parent(s) 1995fc658ad6
    divergent with:
    (01a3e66ba030 ); common evolution ancestor: 3efa43a7427b
    (add9a356b8cf ); common evolution ancestor: 3efa43a7427b
...


```


More information about the Mercurial-devel mailing list