Mercurial > public > mercurial-scm > hg-stable
diff tests/test-template-map.t @ 43101:1d12ae5096d1
formatter: map -Tjson(...) and -Tcbor(...) to templater
Even though custom JSON output could be generated by using
--config template.json="{dict(...)|json}" ..., doing that is tedious because
of the trailing comma handling.
This patch introduces special syntax for JSON/CBOR formats. -Tjson(...) is
translated to template as if function-style template definition were
supported:
[templates]
json(...) = "{dict(...)|json}"
json(...):docheader = "[\n "
json(...):docfooter = "\n]\n"
json(...):separator = ",\n "
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 05 Oct 2019 23:30:09 -0400 |
parents | 90b9a7e06c2c |
children | 829088e87032 |
line wrap: on
line diff
--- a/tests/test-template-map.t Sat Oct 05 23:20:35 2019 -0400 +++ b/tests/test-template-map.t Sat Oct 05 23:30:09 2019 -0400 @@ -736,6 +736,18 @@ } ] + $ hg log -r . -T'cbor(rev, node|short)' | "$PYTHON" "$TESTTMP/decodecborarray.py" + [ + { + 'node': '95c24699272e', + 'rev': 8 + } + ] + + $ hg log -r . -T'cbor()' | "$PYTHON" "$TESTTMP/decodecborarray.py" + [ + {} + ] Test JSON style: @@ -1101,6 +1113,17 @@ } ] + $ hg log -l2 -T'json(rev, parents)' + [ + {"parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"], "rev": 8}, + {"parents": ["0000000000000000000000000000000000000000"], "rev": 7} + ] + + $ hg log -r. -T'json()' + [ + {} + ] + Other unsupported formatter styles: $ hg log -qr . -Tpickle @@ -1110,6 +1133,24 @@ abort: "debug" not in template map [255] +Unparsable function-style references: + + $ hg log -qr . -T'json(-)' + hg: parse error at 6: not a prefix: ) + (json(-) + ^ here) + [255] + +For backward compatibility, the following examples are not parsed as +function-style references: + + $ hg log -qr . -T'cbor(rev' + cbor(rev (no-eol) + $ hg log -qr . -T'json (rev)' + json (rev) (no-eol) + $ hg log -qr . -T'json(x="{rev}")' + json(x="8") (no-eol) + Error if style not readable: #if unix-permissions no-root