##// END OF EJS Templates
help: adding example 'extras' printing to 'hg help templates'
Matthew Turk -
r20016:f4b3bdc3 default
parent child Browse files
Show More
@@ -1,104 +1,108 b''
1 Mercurial allows you to customize output of commands through
1 Mercurial allows you to customize output of commands through
2 templates. You can either pass in a template from the command
2 templates. You can either pass in a template from the command
3 line, via the --template option, or select an existing
3 line, via the --template option, or select an existing
4 template-style (--style).
4 template-style (--style).
5
5
6 You can customize output for any "log-like" command: log,
6 You can customize output for any "log-like" command: log,
7 outgoing, incoming, tip, parents, heads and glog.
7 outgoing, incoming, tip, parents, heads and glog.
8
8
9 Five styles are packaged with Mercurial: default (the style used
9 Five styles are packaged with Mercurial: default (the style used
10 when no explicit preference is passed), compact, changelog, phases
10 when no explicit preference is passed), compact, changelog, phases
11 and xml.
11 and xml.
12 Usage::
12 Usage::
13
13
14 $ hg log -r1 --style changelog
14 $ hg log -r1 --style changelog
15
15
16 A template is a piece of text, with markup to invoke variable
16 A template is a piece of text, with markup to invoke variable
17 expansion::
17 expansion::
18
18
19 $ hg log -r1 --template "{node}\n"
19 $ hg log -r1 --template "{node}\n"
20 b56ce7b07c52de7d5fd79fb89701ea538af65746
20 b56ce7b07c52de7d5fd79fb89701ea538af65746
21
21
22 Strings in curly braces are called keywords. The availability of
22 Strings in curly braces are called keywords. The availability of
23 keywords depends on the exact context of the templater. These
23 keywords depends on the exact context of the templater. These
24 keywords are usually available for templating a log-like command:
24 keywords are usually available for templating a log-like command:
25
25
26 .. keywordsmarker
26 .. keywordsmarker
27
27
28 The "date" keyword does not produce human-readable output. If you
28 The "date" keyword does not produce human-readable output. If you
29 want to use a date in your output, you can use a filter to process
29 want to use a date in your output, you can use a filter to process
30 it. Filters are functions which return a string based on the input
30 it. Filters are functions which return a string based on the input
31 variable. Be sure to use the stringify filter first when you're
31 variable. Be sure to use the stringify filter first when you're
32 applying a string-input filter to a list-like input variable.
32 applying a string-input filter to a list-like input variable.
33 You can also use a chain of filters to get the desired output::
33 You can also use a chain of filters to get the desired output::
34
34
35 $ hg tip --template "{date|isodate}\n"
35 $ hg tip --template "{date|isodate}\n"
36 2008-08-21 18:22 +0000
36 2008-08-21 18:22 +0000
37
37
38 List of filters:
38 List of filters:
39
39
40 .. filtersmarker
40 .. filtersmarker
41
41
42 Note that a filter is nothing more than a function call, i.e.
42 Note that a filter is nothing more than a function call, i.e.
43 ``expr|filter`` is equivalent to ``filter(expr)``.
43 ``expr|filter`` is equivalent to ``filter(expr)``.
44
44
45 In addition to filters, there are some basic built-in functions:
45 In addition to filters, there are some basic built-in functions:
46
46
47 - date(date[, fmt])
47 - date(date[, fmt])
48
48
49 - fill(text[, width])
49 - fill(text[, width])
50
50
51 - get(dict, key)
51 - get(dict, key)
52
52
53 - if(expr, then[, else])
53 - if(expr, then[, else])
54
54
55 - ifeq(expr, expr, then[, else])
55 - ifeq(expr, expr, then[, else])
56
56
57 - join(list, sep)
57 - join(list, sep)
58
58
59 - label(label, expr)
59 - label(label, expr)
60
60
61 - rstdoc(text, style)
61 - rstdoc(text, style)
62
62
63 - strip(text[, chars])
63 - strip(text[, chars])
64
64
65 - sub(pat, repl, expr)
65 - sub(pat, repl, expr)
66
66
67 Also, for any expression that returns a list, there is a list operator:
67 Also, for any expression that returns a list, there is a list operator:
68
68
69 - expr % "{template}"
69 - expr % "{template}"
70
70
71 Some sample command line templates:
71 Some sample command line templates:
72
72
73 - Format lists, e.g. files::
73 - Format lists, e.g. files::
74
74
75 $ hg log -r 0 --template "files:\n{files % ' {file}\n'}"
75 $ hg log -r 0 --template "files:\n{files % ' {file}\n'}"
76
76
77 - Join the list of files with a ", "::
77 - Join the list of files with a ", "::
78
78
79 $ hg log -r 0 --template "files: {join(files, ', ')}\n"
79 $ hg log -r 0 --template "files: {join(files, ', ')}\n"
80
80
81 - Format date::
81 - Format date::
82
82
83 $ hg log -r 0 --template "{date(date, '%Y')}\n"
83 $ hg log -r 0 --template "{date(date, '%Y')}\n"
84
84
85 - Output the description set to a fill-width of 30::
85 - Output the description set to a fill-width of 30::
86
86
87 $ hg log -r 0 --template "{fill(desc, '30')}"
87 $ hg log -r 0 --template "{fill(desc, '30')}"
88
88
89 - Use a conditional to test for the default branch::
89 - Use a conditional to test for the default branch::
90
90
91 $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch',
91 $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch',
92 'on branch {branch}')}\n"
92 'on branch {branch}')}\n"
93
93
94 - Append a newline if not empty::
94 - Append a newline if not empty::
95
95
96 $ hg tip --template "{if(author, '{author}\n')}"
96 $ hg tip --template "{if(author, '{author}\n')}"
97
97
98 - Label the output for use with the color extension::
98 - Label the output for use with the color extension::
99
99
100 $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n"
100 $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n"
101
101
102 - Invert the firstline filter, i.e. everything but the first line::
102 - Invert the firstline filter, i.e. everything but the first line::
103
103
104 $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n"
104 $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n"
105
106 - Display the contents of the 'extra' field, one per line::
107
108 $ hg log -r 0 --template "{join(extras, '\n')}\n"
General Comments 0
You need to be logged in to leave comments. Login now