Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
43100:90b9a7e06c2c | 43101:1d12ae5096d1 |
---|---|
734 ], | 734 ], |
735 'user': 'test' | 735 'user': 'test' |
736 } | 736 } |
737 ] | 737 ] |
738 | 738 |
739 $ hg log -r . -T'cbor(rev, node|short)' | "$PYTHON" "$TESTTMP/decodecborarray.py" | |
740 [ | |
741 { | |
742 'node': '95c24699272e', | |
743 'rev': 8 | |
744 } | |
745 ] | |
746 | |
747 $ hg log -r . -T'cbor()' | "$PYTHON" "$TESTTMP/decodecborarray.py" | |
748 [ | |
749 {} | |
750 ] | |
739 | 751 |
740 Test JSON style: | 752 Test JSON style: |
741 | 753 |
742 $ hg log -k nosuch -Tjson | 754 $ hg log -k nosuch -Tjson |
743 [ | 755 [ |
1099 "tags": [], | 1111 "tags": [], |
1100 "user": "User Name <user@hostname>" | 1112 "user": "User Name <user@hostname>" |
1101 } | 1113 } |
1102 ] | 1114 ] |
1103 | 1115 |
1116 $ hg log -l2 -T'json(rev, parents)' | |
1117 [ | |
1118 {"parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"], "rev": 8}, | |
1119 {"parents": ["0000000000000000000000000000000000000000"], "rev": 7} | |
1120 ] | |
1121 | |
1122 $ hg log -r. -T'json()' | |
1123 [ | |
1124 {} | |
1125 ] | |
1126 | |
1104 Other unsupported formatter styles: | 1127 Other unsupported formatter styles: |
1105 | 1128 |
1106 $ hg log -qr . -Tpickle | 1129 $ hg log -qr . -Tpickle |
1107 abort: "pickle" not in template map | 1130 abort: "pickle" not in template map |
1108 [255] | 1131 [255] |
1109 $ hg log -qr . -Tdebug | 1132 $ hg log -qr . -Tdebug |
1110 abort: "debug" not in template map | 1133 abort: "debug" not in template map |
1111 [255] | 1134 [255] |
1135 | |
1136 Unparsable function-style references: | |
1137 | |
1138 $ hg log -qr . -T'json(-)' | |
1139 hg: parse error at 6: not a prefix: ) | |
1140 (json(-) | |
1141 ^ here) | |
1142 [255] | |
1143 | |
1144 For backward compatibility, the following examples are not parsed as | |
1145 function-style references: | |
1146 | |
1147 $ hg log -qr . -T'cbor(rev' | |
1148 cbor(rev (no-eol) | |
1149 $ hg log -qr . -T'json (rev)' | |
1150 json (rev) (no-eol) | |
1151 $ hg log -qr . -T'json(x="{rev}")' | |
1152 json(x="8") (no-eol) | |
1112 | 1153 |
1113 Error if style not readable: | 1154 Error if style not readable: |
1114 | 1155 |
1115 #if unix-permissions no-root | 1156 #if unix-permissions no-root |
1116 $ touch q | 1157 $ touch q |