# HG changeset patch # User Sean Farley # Date 1358901623 21600 # Node ID 3aa8b4b36b6487ae5690ac62561536a7ed30cb6b # Parent a2e9fe93d9eaba4ad2727d6bcde3afe3985ac00b help: add documentation for new template functions diff -r a2e9fe93d9ea -r 3aa8b4b36b64 mercurial/help/templates.txt --- a/mercurial/help/templates.txt Tue Jan 22 11:39:14 2013 +0100 +++ b/mercurial/help/templates.txt Tue Jan 22 18:40:23 2013 -0600 @@ -38,3 +38,61 @@ List of filters: .. filtersmarker + +Note that a filter is nothing more than a function call, i.e. +``expr|filter`` is equivalent to ``filter(expr)``. + +In addition to filters, there are some basic built-in functions: + +- if(expr, then[, else]) + +- ifeq(expr, expr, then[, else]) + +- sub(pat, repl, expr) + +- join(list, sep) + +- label(label, expr) + +- date(date[, fmt]) + +- fill(text[, width]) + +Also, for any expression that returns a list, there is a list operator: + +- expr % "{template}" + +Some sample command line templates: + +- Format lists, e.g. files:: + + $ hg log -r 0 --template "files:\n{files % ' {file}\n'}" + +- Join the list of files with a ", ":: + + $ hg log -r 0 --template "files: {join(files, ', ')}\n" + +- Format date:: + + $ hg log -r 0 --template "{date(date, '%Y')}\n" + +- Output the description set to a fill-width of 30:: + + $ hg log -r 0 --template "{fill(desc, '30')}" + +- Use a conditional to test for the default branch:: + + $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch', + 'on branch {branch}')}\n" + +- Append a newline if not empty:: + + $ hg tip --template "{if(author, '{author}\n')}" + +- Label the output for use with the color extension:: + + $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n" + +- Invert the firstline filter, i.e. everything but the first line:: + + $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n"