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