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