Mercurial > public > mercurial-scm > hg-stable
diff tests/test-template-functions.t @ 44597:fc1fa3a07af6
templater: introduce wrapper for smartset (API)
I want to add a template function which takes a revset as an argument:
{somefunc(..., revset(...))}
^^^^^^^^^^^
evaluates to a revslist
This wrapper will provide a method to get an underlying smartset. It should
also be good for performance since count(revset(...)) will no longer have to
fully consume the smartset for example, but that isn't the point of this
change.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 15 Mar 2020 15:12:44 +0900 |
parents | 967e2e81f762 |
children | 7333e8bb9781 |
line wrap: on
line diff
--- a/tests/test-template-functions.t Fri Mar 20 23:30:23 2020 -0400 +++ b/tests/test-template-functions.t Sun Mar 15 15:12:44 2020 +0900 @@ -820,6 +820,8 @@ {"branch": "default"} $ hg log -r0 -T '{date|json}\n' [0, 0] + $ hg log -r0 -T '{revset(":")|json}\n' + [0, 1] Test json filter applied to map result: @@ -1263,6 +1265,28 @@ 5:13207e5a10d9fd28ec424934298e176197f2c67f, 4:bbe44766e73d5f11ed2177f1838de10c53ef3e74 +for historical reasons, revset() supports old-style list template + + $ hg log -T '{revset(":")}\n' -l1 \ + > --config templates.start_revisions='"["' \ + > --config templates.end_revisions='"]"' \ + > --config templates.revision='"{revision}, "' \ + > --config templates.last_revision='"{revision}"' + [0, 1, 2] + $ hg log -T '{revset(":") % " {revision}"}\n' -l1 + 0 1 2 + +but a filtered one doesn't + + $ hg log -T '{filter(revset(":"), ifeq(rev, 1, "", "y"))}\n' -l1 \ + > --config templates.start_revisions='"["' \ + > --config templates.end_revisions='"]"' \ + > --config templates.revision='"{revision}, "' \ + > --config templates.last_revision='"{revision}"' + 0 2 + $ hg log -T '{filter(revset(":"), ifeq(rev, 1, "", "y")) % "x{revision}"}\n' -l1 + xx + %d parameter handling: $ hg log -T '{revset("%d", rev)}\n' -r'wdir()' @@ -1318,6 +1342,13 @@ hg: parse error: invalid argument for revspec [255] +Invalid operation on revset() + + $ hg log -T '{get(revset(":"), "foo")}\n' + hg: parse error: not a dictionary + (get() expects a dict as first argument) + [255] + Test files function $ hg log -T "{rev}\n{join(files('*'), '\n')}\n" @@ -1568,6 +1599,23 @@ } ] + $ hg log -T "{revset(':')|cbor}" -R a -l1 | "$PYTHON" "$TESTTMP/decodecbor.py" + [ + [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10 + ] + ] + json filter should escape HTML tags so that the output can be embedded in hgweb: $ hg log -T "{'<foo@example.org>'|json}\n" -R a -l1