annotate mercurial/help/templates.txt @ 21945:d603e7333281 stable

help: drop reference to glog in templates topic
author Matt Mackall <mpm@selenic.com>
date Fri, 25 Jul 2014 15:38:26 -0500
parents 8534e670f4ee
children 868e2cea3ea0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
1 Mercurial allows you to customize output of commands through
21943
8534e670f4ee help: use --template to specify existing style
Yuya Nishihara <yuya@tcha.org>
parents: 21846
diff changeset
2 templates. You can either pass in a template or select an existing
8534e670f4ee help: use --template to specify existing style
Yuya Nishihara <yuya@tcha.org>
parents: 21846
diff changeset
3 template-style from the command line, via the --template option.
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
4
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
5 You can customize output for any "log-like" command: log,
21945
d603e7333281 help: drop reference to glog in templates topic
Matt Mackall <mpm@selenic.com>
parents: 21943
diff changeset
6 outgoing, incoming, tip, parents, and heads.
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
7
19126
5c5152af0d15 log-style: add a log style that is default+phase (issue3436)
Iulian Stana <julian.stana@gmail.com>
parents: 18747
diff changeset
8 Five styles are packaged with Mercurial: default (the style used
5c5152af0d15 log-style: add a log style that is default+phase (issue3436)
Iulian Stana <julian.stana@gmail.com>
parents: 18747
diff changeset
9 when no explicit preference is passed), compact, changelog, phases
11034
3b89899934a6 log: document the new xml style
Dan Connolly <http://www.w3.org/People/Connolly/>
parents: 10759
diff changeset
10 and xml.
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
11 Usage::
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
12
21943
8534e670f4ee help: use --template to specify existing style
Yuya Nishihara <yuya@tcha.org>
parents: 21846
diff changeset
13 $ hg log -r1 --template changelog
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
14
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
15 A template is a piece of text, with markup to invoke variable
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
16 expansion::
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
17
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
18 $ hg log -r1 --template "{node}\n"
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
19 b56ce7b07c52de7d5fd79fb89701ea538af65746
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
20
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
21 Strings in curly braces are called keywords. The availability of
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
22 keywords depends on the exact context of the templater. These
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
23 keywords are usually available for templating a log-like command:
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
24
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13498
diff changeset
25 .. keywordsmarker
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
26
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
27 The "date" keyword does not produce human-readable output. If you
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
28 want to use a date in your output, you can use a filter to process
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
29 it. Filters are functions which return a string based on the input
10759
9f6e30a89f11 help: point out need for stringification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10066
diff changeset
30 variable. Be sure to use the stringify filter first when you're
9f6e30a89f11 help: point out need for stringification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10066
diff changeset
31 applying a string-input filter to a list-like input variable.
9f6e30a89f11 help: point out need for stringification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10066
diff changeset
32 You can also use a chain of filters to get the desired output::
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
33
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
34 $ hg tip --template "{date|isodate}\n"
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
35 2008-08-21 18:22 +0000
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
36
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
37 List of filters:
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
38
13591
264f292a0c6f templatefilters: move doc from templates.txt to docstrings
Patrick Mezard <pmezard@gmail.com>
parents: 13585
diff changeset
39 .. filtersmarker
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
40
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
41 Note that a filter is nothing more than a function call, i.e.
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
42 ``expr|filter`` is equivalent to ``filter(expr)``.
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
43
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
44 In addition to filters, there are some basic built-in functions:
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
45
18582
ef78450c8df6 templater: add get() function to access dict element (e.g. extra)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 18465
diff changeset
46 - date(date[, fmt])
ef78450c8df6 templater: add get() function to access dict element (e.g. extra)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 18465
diff changeset
47
ef78450c8df6 templater: add get() function to access dict element (e.g. extra)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 18465
diff changeset
48 - fill(text[, width])
ef78450c8df6 templater: add get() function to access dict element (e.g. extra)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 18465
diff changeset
49
ef78450c8df6 templater: add get() function to access dict element (e.g. extra)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 18465
diff changeset
50 - get(dict, key)
ef78450c8df6 templater: add get() function to access dict element (e.g. extra)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 18465
diff changeset
51
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
52 - if(expr, then[, else])
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
53
20531
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
54 - ifcontains(expr, expr, then[, else])
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
55
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
56 - ifeq(expr, expr, then[, else])
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
57
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
58 - join(list, sep)
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
59
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
60 - label(label, expr)
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
61
20531
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
62 - revset(query[, formatargs])
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
63
18747
f5db3092790f hgweb: generate HTML documentation
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 18582
diff changeset
64 - rstdoc(text, style)
f5db3092790f hgweb: generate HTML documentation
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 18582
diff changeset
65
20531
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
66 - shortest(node)
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
67
21821
4a445dc5abff templater: introduce startswith function
Ryan McElroy <rmcelroy@fb.com>
parents: 21820
diff changeset
68 - startswith(string, text)
4a445dc5abff templater: introduce startswith function
Ryan McElroy <rmcelroy@fb.com>
parents: 21820
diff changeset
69
19390
3af3a165db18 templater: sort functions alphabetically, as filters are
Alexander Plavin <me@aplavin.ru>
parents: 19330
diff changeset
70 - strip(text[, chars])
3af3a165db18 templater: sort functions alphabetically, as filters are
Alexander Plavin <me@aplavin.ru>
parents: 19330
diff changeset
71
3af3a165db18 templater: sort functions alphabetically, as filters are
Alexander Plavin <me@aplavin.ru>
parents: 19330
diff changeset
72 - sub(pat, repl, expr)
19330
867b9957d895 templater: add strip function with chars as an extra argument
Alexander Plavin <me@aplavin.ru>
parents: 19126
diff changeset
73
21846
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
74 - word(number, text[, separator])
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
75
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
76 Also, for any expression that returns a list, there is a list operator:
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
77
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
78 - expr % "{template}"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
79
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
80 Some sample command line templates:
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
81
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
82 - Format lists, e.g. files::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
83
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
84 $ hg log -r 0 --template "files:\n{files % ' {file}\n'}"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
85
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
86 - Join the list of files with a ", "::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
87
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
88 $ hg log -r 0 --template "files: {join(files, ', ')}\n"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
89
21820
cce404b0c918 templatefilter: add splitlines function
Ryan McElroy <rmcelroy@fb.com>
parents: 20531
diff changeset
90 - Modify each line of a commit description::
cce404b0c918 templatefilter: add splitlines function
Ryan McElroy <rmcelroy@fb.com>
parents: 20531
diff changeset
91
cce404b0c918 templatefilter: add splitlines function
Ryan McElroy <rmcelroy@fb.com>
parents: 20531
diff changeset
92 $ hg log --template "{splitlines(desc) % '**** {line}\n'}"
cce404b0c918 templatefilter: add splitlines function
Ryan McElroy <rmcelroy@fb.com>
parents: 20531
diff changeset
93
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
94 - Format date::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
95
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
96 $ hg log -r 0 --template "{date(date, '%Y')}\n"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
97
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
98 - Output the description set to a fill-width of 30::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
99
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
100 $ hg log -r 0 --template "{fill(desc, '30')}"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
101
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
102 - Use a conditional to test for the default branch::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
103
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
104 $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch',
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
105 'on branch {branch}')}\n"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
106
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
107 - Append a newline if not empty::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
108
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
109 $ hg tip --template "{if(author, '{author}\n')}"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
110
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
111 - Label the output for use with the color extension::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
112
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
113 $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
114
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
115 - Invert the firstline filter, i.e. everything but the first line::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
116
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
117 $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n"
20016
f4b3bdc3019e help: adding example 'extras' printing to 'hg help templates'
Matthew Turk <matthewturk@gmail.com>
parents: 19390
diff changeset
118
f4b3bdc3019e help: adding example 'extras' printing to 'hg help templates'
Matthew Turk <matthewturk@gmail.com>
parents: 19390
diff changeset
119 - Display the contents of the 'extra' field, one per line::
f4b3bdc3019e help: adding example 'extras' printing to 'hg help templates'
Matthew Turk <matthewturk@gmail.com>
parents: 19390
diff changeset
120
20170
574f3b6e0e8b help: fix formatting of template example
Steve Hoelzer <shoelzer@gmail.com>
parents: 20016
diff changeset
121 $ hg log -r 0 --template "{join(extras, '\n')}\n"
20531
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
122
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
123 - Mark the current bookmark with '*'::
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
124
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
125 $ hg log --template "{bookmarks % '{bookmark}{ifeq(bookmark, current, \"*\")} '}\n"
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
126
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
127 - Mark the working copy parent with '@'::
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
128
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
129 $ hg log --template "{ifcontains(rev, revset('.'), '@')}\n"
21821
4a445dc5abff templater: introduce startswith function
Ryan McElroy <rmcelroy@fb.com>
parents: 21820
diff changeset
130
4a445dc5abff templater: introduce startswith function
Ryan McElroy <rmcelroy@fb.com>
parents: 21820
diff changeset
131 - Show only commit descriptions that start with "template"::
4a445dc5abff templater: introduce startswith function
Ryan McElroy <rmcelroy@fb.com>
parents: 21820
diff changeset
132
4a445dc5abff templater: introduce startswith function
Ryan McElroy <rmcelroy@fb.com>
parents: 21820
diff changeset
133 $ hg log --template "{startswith(\"template\", firstline(desc))}\n"
21846
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
134
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
135 - Print the first word of each line of a commit message::
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
136
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
137 $ hg log --template "{word(\"0\", desc)}\n"