changeset 18465:3aa8b4b36b64 stable

help: add documentation for new template functions
author Sean Farley <sean.michael.farley@gmail.com>
date Tue, 22 Jan 2013 18:40:23 -0600
parents a2e9fe93d9ea
children ac0c12123743
files mercurial/help/templates.txt
diffstat 1 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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"