2009-10-04 14:18:43 +04:00
|
|
|
Mercurial allows you to customize output of commands through
|
2014-07-21 06:44:20 +04:00
|
|
|
templates. You can either pass in a template or select an existing
|
|
|
|
template-style from the command line, via the --template option.
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2009-10-04 14:18:43 +04:00
|
|
|
You can customize output for any "log-like" command: log,
|
2014-07-26 00:38:26 +04:00
|
|
|
outgoing, incoming, tip, parents, and heads.
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2014-07-26 00:51:42 +04:00
|
|
|
Some built-in styles are packaged with Mercurial. These can be listed
|
|
|
|
with :hg:`log --template list`. Example usage::
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2014-07-26 00:51:42 +04:00
|
|
|
$ hg log -r1.0::1.1 --template changelog
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2009-10-04 14:18:43 +04:00
|
|
|
A template is a piece of text, with markup to invoke variable
|
|
|
|
expansion::
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2009-10-04 14:18:43 +04:00
|
|
|
$ hg log -r1 --template "{node}\n"
|
|
|
|
b56ce7b07c52de7d5fd79fb89701ea538af65746
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2009-10-04 14:18:43 +04:00
|
|
|
Strings in curly braces are called keywords. The availability of
|
|
|
|
keywords depends on the exact context of the templater. These
|
|
|
|
keywords are usually available for templating a log-like command:
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2011-03-12 14:46:31 +03:00
|
|
|
.. keywordsmarker
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2009-10-04 14:18:43 +04:00
|
|
|
The "date" keyword does not produce human-readable output. If you
|
|
|
|
want to use a date in your output, you can use a filter to process
|
|
|
|
it. Filters are functions which return a string based on the input
|
2010-03-23 13:48:14 +03:00
|
|
|
variable. Be sure to use the stringify filter first when you're
|
|
|
|
applying a string-input filter to a list-like input variable.
|
|
|
|
You can also use a chain of filters to get the desired output::
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2009-10-04 14:18:43 +04:00
|
|
|
$ hg tip --template "{date|isodate}\n"
|
|
|
|
2008-08-21 18:22 +0000
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2009-10-04 14:18:43 +04:00
|
|
|
List of filters:
|
2009-10-04 11:59:13 +04:00
|
|
|
|
2011-03-12 14:46:31 +03:00
|
|
|
.. filtersmarker
|
2013-01-23 04:40:23 +04:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
2015-04-02 06:23:58 +03:00
|
|
|
.. functionsmarker
|
2014-06-13 05:02:23 +04:00
|
|
|
|
2013-01-23 04:40:23 +04:00
|
|
|
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"
|
|
|
|
|
2014-06-13 04:45:41 +04:00
|
|
|
- Modify each line of a commit description::
|
|
|
|
|
|
|
|
$ hg log --template "{splitlines(desc) % '**** {line}\n'}"
|
|
|
|
|
2013-01-23 04:40:23 +04:00
|
|
|
- Format date::
|
|
|
|
|
|
|
|
$ hg log -r 0 --template "{date(date, '%Y')}\n"
|
|
|
|
|
|
|
|
- Output the description set to a fill-width of 30::
|
|
|
|
|
2015-05-02 09:51:57 +03:00
|
|
|
$ hg log -r 0 --template "{fill(desc, 30)}"
|
2013-01-23 04:40:23 +04:00
|
|
|
|
|
|
|
- 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"
|
2013-11-16 03:09:02 +04:00
|
|
|
|
|
|
|
- Display the contents of the 'extra' field, one per line::
|
|
|
|
|
2013-12-11 21:33:58 +04:00
|
|
|
$ hg log -r 0 --template "{join(extras, '\n')}\n"
|
2014-02-19 02:48:56 +04:00
|
|
|
|
2015-05-29 06:03:42 +03:00
|
|
|
- Mark the active bookmark with '*'::
|
2014-02-19 02:48:56 +04:00
|
|
|
|
2015-05-29 06:03:42 +03:00
|
|
|
$ hg log --template "{bookmarks % '{bookmark}{ifeq(bookmark, active, \"*\")} '}\n"
|
2014-02-19 02:48:56 +04:00
|
|
|
|
|
|
|
- Mark the working copy parent with '@'::
|
|
|
|
|
|
|
|
$ hg log --template "{ifcontains(rev, revset('.'), '@')}\n"
|
2014-06-13 04:53:37 +04:00
|
|
|
|
|
|
|
- Show only commit descriptions that start with "template"::
|
|
|
|
|
|
|
|
$ hg log --template "{startswith(\"template\", firstline(desc))}\n"
|
2014-06-13 05:02:23 +04:00
|
|
|
|
|
|
|
- Print the first word of each line of a commit message::
|
|
|
|
|
2015-05-02 09:51:57 +03:00
|
|
|
$ hg log --template "{word(0, desc)}\n"
|