[PATCH 6 of 6 json-style] tests: add tests for json output from hgweb

Gregory Szorc gregory.szorc at gmail.com
Mon Jan 5 20:00:58 CST 2015


On 1/1/15 3:26 PM, Matt Mackall wrote:
> On Wed, 2014-12-31 at 14:45 -0800, Gregory Szorc wrote:
>> # HG changeset patch
>> # User Gregory Szorc <gregory.szorc at gmail.com>
>> # Date 1420065389 28800
>> #      Wed Dec 31 14:36:29 2014 -0800
>> # Node ID 375310e882793f02023305f1065f616b0b42ab88
>> # Parent  8a88b921f7b9b467046496ab6aa99d2589dd935c
>> tests: add tests for json output from hgweb
>
>> +  {"author": "test", "branch": [], "child": [], "date": [0.0, 0],
>> "desc": "move foo", "extra": {"branch": "default"}, "file": "foo-new",
>> "node": "78896eb0e102174ce9278438a95e12543e4367a7", "parent":
>> [{"branch": "default", "date": [0.0, 0], "description": "modify foo",
>> "file": "foo", "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
>> "rev": 1, "user": "test"}], "path": "/", "permissions": "", "rename":
>> [{"file": "foo", "node": "cebda196bdbe7661cec847739e7c5de89ec6e5a5"}],
>> "rev": 3, "text": [{"line": "bar\n", "lineid": "l1", "linenumber":"
>> 1", "parity": 0}]} (no-eol)
>
> This should be aiming to agree with the schema produced by hg log -T
> json today. Eg:
>
> $ hg log -Tjson -l1
> [
>   {
>    "rev": 26053,
>    "node": "3314664606e63e0ae263b71f5210e8153291efe8",
>    "branch": "default",
>    "phase": "public",
>    "user": "Matt Mackall <mpm at selenic.com>",
>    "date": [1420152434, 21600],
>    "desc": "merge with stable",
>    "bookmarks": ["@"],
>    "tags": ["tip"],
>    "parents": ["28a302e9225d05b35d61da6f70e7187ad3ce8d7c",
> "4308087f2fbd90b5beaac53a71d6264684ee0c40"]
>   }
> ]
>
> Same story for other commands.
>
> With your jsonengine approach, this is going to be a real pain to
> achieve. It'll mean modifying hgweb and every other style to make the
> ancient internal hgweb element names and structures agree with what's
> being done on the command line. Or, alternately, having a system to do
> some transformations inside jsonengine.
>
> But we've already got a templater for that. My position is still that we
> should implement this by adding a mercurial/templates/json with a bunch
> of boring templates like we have for raw. Same for xml.

Can do!

How much leeway do I have with consistency with the CLI? For example, 
the CLI currently renders things like diffstat in the human readable 
form. e.g. "9 +++++----\n tests/test-annotate.t". I think JSON output, 
being destined for machines, should preserve the original metadata 
instead of munge it into an unstructured text field. I'll code patches 
with what I think is more sensible unless I hear otherwise.

Also, I'm finding things like lack of templatekw.showlist usage to be 
quite annoying. e.g. I can't utilize the "start_foo" magic to properly 
encode JSON lists. I'm only now realizing how different the CLI and web 
templating systems are :/ Because of these differences, it looks like I 
may have to pass some variables to the web templater multiple times, 
just encoded slightly differently in order to facilitate proper JSON 
encoding. Or maybe I'll invent some one-off filters defined only for the 
web templater. It's a nice little can of worms in here. Now I understand 
why this wasn't done sooner :)



More information about the Mercurial-devel mailing list