##// END OF EJS Templates
merge with stable
Matt Mackall -
r22295:926bc0d3 merge default
parent child Browse files
Show More
@@ -1,135 +1,137 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 or select an existing
2 templates. You can either pass in a template or select an existing
3 template-style from the command line, via the --template option.
3 template-style from the command line, via the --template option.
4
4
5 You can customize output for any "log-like" command: log,
5 You can customize output for any "log-like" command: log,
6 outgoing, incoming, tip, parents, and heads.
6 outgoing, incoming, tip, parents, and heads.
7
7
8 Some built-in styles are packaged with Mercurial. These can be listed
8 Some built-in styles are packaged with Mercurial. These can be listed
9 with :hg:`log --template list`. Example usage::
9 with :hg:`log --template list`. Example usage::
10
10
11 $ hg log -r1.0::1.1 --template changelog
11 $ hg log -r1.0::1.1 --template changelog
12
12
13 A template is a piece of text, with markup to invoke variable
13 A template is a piece of text, with markup to invoke variable
14 expansion::
14 expansion::
15
15
16 $ hg log -r1 --template "{node}\n"
16 $ hg log -r1 --template "{node}\n"
17 b56ce7b07c52de7d5fd79fb89701ea538af65746
17 b56ce7b07c52de7d5fd79fb89701ea538af65746
18
18
19 Strings in curly braces are called keywords. The availability of
19 Strings in curly braces are called keywords. The availability of
20 keywords depends on the exact context of the templater. These
20 keywords depends on the exact context of the templater. These
21 keywords are usually available for templating a log-like command:
21 keywords are usually available for templating a log-like command:
22
22
23 .. keywordsmarker
23 .. keywordsmarker
24
24
25 The "date" keyword does not produce human-readable output. If you
25 The "date" keyword does not produce human-readable output. If you
26 want to use a date in your output, you can use a filter to process
26 want to use a date in your output, you can use a filter to process
27 it. Filters are functions which return a string based on the input
27 it. Filters are functions which return a string based on the input
28 variable. Be sure to use the stringify filter first when you're
28 variable. Be sure to use the stringify filter first when you're
29 applying a string-input filter to a list-like input variable.
29 applying a string-input filter to a list-like input variable.
30 You can also use a chain of filters to get the desired output::
30 You can also use a chain of filters to get the desired output::
31
31
32 $ hg tip --template "{date|isodate}\n"
32 $ hg tip --template "{date|isodate}\n"
33 2008-08-21 18:22 +0000
33 2008-08-21 18:22 +0000
34
34
35 List of filters:
35 List of filters:
36
36
37 .. filtersmarker
37 .. filtersmarker
38
38
39 Note that a filter is nothing more than a function call, i.e.
39 Note that a filter is nothing more than a function call, i.e.
40 ``expr|filter`` is equivalent to ``filter(expr)``.
40 ``expr|filter`` is equivalent to ``filter(expr)``.
41
41
42 In addition to filters, there are some basic built-in functions:
42 In addition to filters, there are some basic built-in functions:
43
43
44 - date(date[, fmt])
44 - date(date[, fmt])
45
45
46 - fill(text[, width])
46 - fill(text[, width])
47
47
48 - get(dict, key)
48 - get(dict, key)
49
49
50 - if(expr, then[, else])
50 - if(expr, then[, else])
51
51
52 - ifcontains(expr, expr, then[, else])
52 - ifcontains(expr, expr, then[, else])
53
53
54 - ifeq(expr, expr, then[, else])
54 - ifeq(expr, expr, then[, else])
55
55
56 - join(list, sep)
56 - join(list, sep)
57
57
58 - label(label, expr)
58 - label(label, expr)
59
59
60 - pad(text, width[, fillchar, right])
61
60 - revset(query[, formatargs])
62 - revset(query[, formatargs])
61
63
62 - rstdoc(text, style)
64 - rstdoc(text, style)
63
65
64 - shortest(node)
66 - shortest(node)
65
67
66 - startswith(string, text)
68 - startswith(string, text)
67
69
68 - strip(text[, chars])
70 - strip(text[, chars])
69
71
70 - sub(pat, repl, expr)
72 - sub(pat, repl, expr)
71
73
72 - word(number, text[, separator])
74 - word(number, text[, separator])
73
75
74 Also, for any expression that returns a list, there is a list operator:
76 Also, for any expression that returns a list, there is a list operator:
75
77
76 - expr % "{template}"
78 - expr % "{template}"
77
79
78 Some sample command line templates:
80 Some sample command line templates:
79
81
80 - Format lists, e.g. files::
82 - Format lists, e.g. files::
81
83
82 $ hg log -r 0 --template "files:\n{files % ' {file}\n'}"
84 $ hg log -r 0 --template "files:\n{files % ' {file}\n'}"
83
85
84 - Join the list of files with a ", "::
86 - Join the list of files with a ", "::
85
87
86 $ hg log -r 0 --template "files: {join(files, ', ')}\n"
88 $ hg log -r 0 --template "files: {join(files, ', ')}\n"
87
89
88 - Modify each line of a commit description::
90 - Modify each line of a commit description::
89
91
90 $ hg log --template "{splitlines(desc) % '**** {line}\n'}"
92 $ hg log --template "{splitlines(desc) % '**** {line}\n'}"
91
93
92 - Format date::
94 - Format date::
93
95
94 $ hg log -r 0 --template "{date(date, '%Y')}\n"
96 $ hg log -r 0 --template "{date(date, '%Y')}\n"
95
97
96 - Output the description set to a fill-width of 30::
98 - Output the description set to a fill-width of 30::
97
99
98 $ hg log -r 0 --template "{fill(desc, '30')}"
100 $ hg log -r 0 --template "{fill(desc, '30')}"
99
101
100 - Use a conditional to test for the default branch::
102 - Use a conditional to test for the default branch::
101
103
102 $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch',
104 $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch',
103 'on branch {branch}')}\n"
105 'on branch {branch}')}\n"
104
106
105 - Append a newline if not empty::
107 - Append a newline if not empty::
106
108
107 $ hg tip --template "{if(author, '{author}\n')}"
109 $ hg tip --template "{if(author, '{author}\n')}"
108
110
109 - Label the output for use with the color extension::
111 - Label the output for use with the color extension::
110
112
111 $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n"
113 $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n"
112
114
113 - Invert the firstline filter, i.e. everything but the first line::
115 - Invert the firstline filter, i.e. everything but the first line::
114
116
115 $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n"
117 $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n"
116
118
117 - Display the contents of the 'extra' field, one per line::
119 - Display the contents of the 'extra' field, one per line::
118
120
119 $ hg log -r 0 --template "{join(extras, '\n')}\n"
121 $ hg log -r 0 --template "{join(extras, '\n')}\n"
120
122
121 - Mark the current bookmark with '*'::
123 - Mark the current bookmark with '*'::
122
124
123 $ hg log --template "{bookmarks % '{bookmark}{ifeq(bookmark, current, \"*\")} '}\n"
125 $ hg log --template "{bookmarks % '{bookmark}{ifeq(bookmark, current, \"*\")} '}\n"
124
126
125 - Mark the working copy parent with '@'::
127 - Mark the working copy parent with '@'::
126
128
127 $ hg log --template "{ifcontains(rev, revset('.'), '@')}\n"
129 $ hg log --template "{ifcontains(rev, revset('.'), '@')}\n"
128
130
129 - Show only commit descriptions that start with "template"::
131 - Show only commit descriptions that start with "template"::
130
132
131 $ hg log --template "{startswith(\"template\", firstline(desc))}\n"
133 $ hg log --template "{startswith(\"template\", firstline(desc))}\n"
132
134
133 - Print the first word of each line of a commit message::
135 - Print the first word of each line of a commit message::
134
136
135 $ hg log --template "{word(\"0\", desc)}\n"
137 $ hg log --template "{word(\"0\", desc)}\n"
General Comments 0
You need to be logged in to leave comments. Login now