Mercurial_ The Definitive Guide - Bryan O'Sullivan [86]
node: String. The changeset identification hash, as a 40-character hexadecimal string.
parents: List of strings. The parents of the changeset.
rev: Integer. The repository-local changeset revision number.
tags: List of strings. Any tags associated with the changeset.
A few simple experiments will show us what to expect when we use these keywords; you can see the results below.
$ hg log -r1 --template 'author: {author}\n'
author: Bryan O'Sullivan $ hg log -r1 --template 'desc:\n{desc}\n' desc: added line to end of < in addition, added a file with the helpful name (at least i hope that some might consider it so) of goodbye. $ hg log -r1 --template 'files: {files}\n' files: goodbye hello $ hg log -r1 --template 'file_adds: {file_adds}\n' file_adds: goodbye $ hg log -r1 --template 'file_dels: {file_dels}\n' file_dels: $ hg log -r1 --template 'node: {node}\n' node: 59ae2fd35d8a09c1532bf5ecd9035b4ac6db2cda $ hg log -r1 --template 'parents: {parents}\n' parents: $ hg log -r1 --template 'rev: {rev}\n' rev: 1 $ hg log -r1 --template 'tags: {tags}\n' tags: mytag As noted above, the date keyword does not produce human-readable output, so we must treat it specially. This involves using a filter; see Filtering Keywords to Change Their Results. $ hg log -r1 --template 'date: {date}\n' date: 1241505885.00 $ hg log -r1 --template 'date: {date|isodate}\n' date: 2009-05-05 06:44 +0000 Escape Sequences Mercurial’s templating engine recognizes the most commonly used escape sequences in strings. When it sees a backslash (\) character, it looks at the following character and substitutes the two characters with a single replacement, as described below: \: Backslash, \, ASCII 134. \n: Newline, ASCII 12. \r: Carriage return, ASCII 15. \t: Tab, ASCII 11. \v: Vertical tab, ASCII 13. \{: Open curly brace, {, ASCII 173. \}: Close curly brace, }, ASCII 175. As indicated above, if you want the expansion of a template to contain a literal \, {, or { character, you must escape it. Filtering Keywords to Change Their Results Some of the results of template expansion are not immediately easy to use. Mercurial lets you specify an optional chain of filters to modify the result of expanding a keyword. You have already seen a common filter, isodate, in action above, to make a date readable. Below is a list of the most commonly used filters that Mercurial supports. While some filters can be applied to any text, others can only be used in specific circumstances. The name of each filter is followed first by an indication of where it can be used, then a description of its effect. addbreaks: Any text. Add an XHTML age: date keyword. Render the age of the date, relative to the current time. Yields a string like 10 minutes. basename: Any text, but most useful for the files keyword and its relatives. Treat the text as a path, and return the basename. For example, foo/bar/baz becomes baz. date: date keyword. Render a date in a similar format to the Unix date command, but with timezone included. Yields a string like Mon Sep 04 15:13:13 2006 -0700. domain: Any text, but most useful for the author keyword. Find the first string that looks like an email address, and extract just the domain component. For example, Bryan O’Sullivan email: Any text, but most useful for the author keyword. Extract the first string that looks like an email address. For example, Bryan O’Sullivan escape: Any text. Replace the special XML/XHTML characters &, <, and > with XML entities. fill68: Any text. Wrap the text to fit in 68 columns. This is useful before you pass text through the tabindent filter, and still want it to fit in an 80-column fixed-font window. fill76: Any text. Wrap the text to fit in 76 columns. firstline: Any text. Yields the first line of text, without
tag before the end of every line except the last. For example, foo\nbar becomes foo
\nbar.