Mercurial > hg-stable
diff tests/test-command-template.t @ 28957:d813132ea361
templater: load and expand aliases by template engine (API) (issue4842)
Now template aliases are fully supported in log and formatter templates.
As I said before, aliases are not expanded in map files. This avoids possible
corruption of our stock styles and web templates. This behavior is undocumented
since no map file nor [templates] section are documented at all. Later on,
we might want to add [aliases] section to map files if it appears to be useful.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 27 Mar 2016 20:59:36 +0900 |
parents | 867d6ba2353d |
children | 77e566fe31ec |
line wrap: on
line diff
--- a/tests/test-command-template.t Sun Apr 03 13:23:40 2016 +0900 +++ b/tests/test-command-template.t Sun Mar 27 20:59:36 2016 +0900 @@ -3693,8 +3693,7 @@ ('string', 'UTC'))) ('symbol', 'isodate')) ('string', '\n')) - hg: parse error: unknown function 'utcdate' - [255] + 0:1e4e1b8f71e0 1970-01-12 13:46 +0000 $ hg debugtemplate -vr0 '{status("A", file_adds)}' (template @@ -3712,8 +3711,7 @@ ('string', ' ') ('symbol', 'file') ('string', '\n')))) - hg: parse error: unknown function 'status' - [255] + A a A unary function alias can be called as a filter: @@ -3735,8 +3733,28 @@ ('string', 'UTC'))) ('symbol', 'isodate')) ('string', '\n')) - hg: parse error: unknown function 'utcdate' - [255] + 1970-01-12 13:46 +0000 + +Aliases should be applied only to command arguments and templates in hgrc. +Otherwise, our stock styles and web templates could be corrupted: + + $ hg log -r0 -T '{rn} {utcdate(date)|isodate}\n' + 0:1e4e1b8f71e0 1970-01-12 13:46 +0000 + + $ hg log -r0 --config ui.logtemplate='"{rn} {utcdate(date)|isodate}\n"' + 0:1e4e1b8f71e0 1970-01-12 13:46 +0000 + + $ cat <<EOF > tmpl + > changeset = 'nothing expanded:{rn}\n' + > EOF + $ hg log -r0 --style ./tmpl + nothing expanded: + +Aliases in formatter: + + $ hg branches -T '{pad(branch, 7)} {rn}\n' + default 6:d41e714fe50d + foo 4:bbe44766e73d Unparsable alias: @@ -3745,6 +3763,9 @@ ('symbol', 'bad')) abort: failed to parse the definition of template alias "bad": at 2: not a prefix: end [255] + $ hg log --config templatealias.bad='x(' -T '{bad}' + abort: failed to parse the definition of template alias "bad": at 2: not a prefix: end + [255] $ cd ..