diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -390,6 +390,14 @@ def person(author): return stringutil.person(author) +@templatefilter(b'reverse') +def reverse(list_): + """List. Reverses the order of list items.""" + if isinstance(list_, list): + return templateutil.hybridlist(list_[::-1], name=b'item') + raise error.ParseError(_(b'not reversible')) + + @templatefilter(b'revescape', intype=bytes) def revescape(text): """Any text. Escapes all "special" characters, except @. diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t --- a/tests/test-template-functions.t +++ b/tests/test-template-functions.t @@ -1718,4 +1718,19 @@ read config options: $ hg log -T "{config('templateconfig', 'knob', if(true, 'foo', 'bar'))}\n" foo +reverse filter: + + $ hg log -T "{'abc\ndef\nghi'|splitlines|reverse}\n" + ghi def abc + + $ hg log -T "{'abc'|reverse}\n" + hg: parse error: not reversible + (incompatible use of template filter 'reverse') + [10] + + $ hg log -T "{date|reverse}\n" + hg: parse error: not reversible + (template filter 'reverse' is not compatible with keyword 'date') + [10] + $ cd ..