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