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