Show More
@@ -23,6 +23,7 from . import ( | |||||
23 | util, |
|
23 | util, | |
24 | ) |
|
24 | ) | |
25 | from .utils import ( |
|
25 | from .utils import ( | |
|
26 | cborutil, | |||
26 | dateutil, |
|
27 | dateutil, | |
27 | stringutil, |
|
28 | stringutil, | |
28 | ) |
|
29 | ) | |
@@ -99,6 +100,11 def basename(path): | |||||
99 | """ |
|
100 | """ | |
100 | return os.path.basename(path) |
|
101 | return os.path.basename(path) | |
101 |
|
102 | |||
|
103 | @templatefilter('cbor') | |||
|
104 | def cbor(obj): | |||
|
105 | """Any object. Serializes the object to CBOR bytes.""" | |||
|
106 | return b''.join(cborutil.streamencode(obj)) | |||
|
107 | ||||
102 | @templatefilter('commondir') |
|
108 | @templatefilter('commondir') | |
103 | def commondir(filelist): |
|
109 | def commondir(filelist): | |
104 | """List of text. Treats each list item as file name with / |
|
110 | """List of text. Treats each list item as file name with / |
@@ -1495,6 +1495,32 Test with non-strings like dates | |||||
1495 | 1200000.00 |
|
1495 | 1200000.00 | |
1496 | 1300000.00 |
|
1496 | 1300000.00 | |
1497 |
|
1497 | |||
|
1498 | Test cbor filter: | |||
|
1499 | ||||
|
1500 | $ cat <<'EOF' > "$TESTTMP/decodecbor.py" | |||
|
1501 | > from __future__ import absolute_import | |||
|
1502 | > from mercurial import pycompat | |||
|
1503 | > from mercurial.utils import ( | |||
|
1504 | > cborutil, | |||
|
1505 | > stringutil, | |||
|
1506 | > ) | |||
|
1507 | > items = cborutil.decodeall(pycompat.stdin.read()) | |||
|
1508 | > pycompat.stdout.write(stringutil.pprint(items, indent=1) + b'\n') | |||
|
1509 | > EOF | |||
|
1510 | ||||
|
1511 | $ hg log -T "{rev|cbor}" -R a -l2 | "$PYTHON" "$TESTTMP/decodecbor.py" | |||
|
1512 | [ | |||
|
1513 | 10, | |||
|
1514 | 9 | |||
|
1515 | ] | |||
|
1516 | ||||
|
1517 | $ hg log -T "{extras|cbor}" -R a -l1 | "$PYTHON" "$TESTTMP/decodecbor.py" | |||
|
1518 | [ | |||
|
1519 | { | |||
|
1520 | 'branch': 'default' | |||
|
1521 | } | |||
|
1522 | ] | |||
|
1523 | ||||
1498 | json filter should escape HTML tags so that the output can be embedded in hgweb: |
|
1524 | json filter should escape HTML tags so that the output can be embedded in hgweb: | |
1499 |
|
1525 | |||
1500 | $ hg log -T "{'<foo@example.org>'|json}\n" -R a -l1 |
|
1526 | $ hg log -T "{'<foo@example.org>'|json}\n" -R a -l1 |
General Comments 0
You need to be logged in to leave comments.
Login now