Show More
@@ -1,107 +1,107 | |||||
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 | .. functionsmarker |
|
44 | .. functionsmarker | |
45 |
|
45 | |||
46 | Also, for any expression that returns a list, there is a list operator: |
|
46 | Also, for any expression that returns a list, there is a list operator: | |
47 |
|
47 | |||
48 | - expr % "{template}" |
|
48 | - expr % "{template}" | |
49 |
|
49 | |||
50 | Some sample command line templates: |
|
50 | Some sample command line templates: | |
51 |
|
51 | |||
52 | - Format lists, e.g. files:: |
|
52 | - Format lists, e.g. files:: | |
53 |
|
53 | |||
54 | $ hg log -r 0 --template "files:\n{files % ' {file}\n'}" |
|
54 | $ hg log -r 0 --template "files:\n{files % ' {file}\n'}" | |
55 |
|
55 | |||
56 | - Join the list of files with a ", ":: |
|
56 | - Join the list of files with a ", ":: | |
57 |
|
57 | |||
58 | $ hg log -r 0 --template "files: {join(files, ', ')}\n" |
|
58 | $ hg log -r 0 --template "files: {join(files, ', ')}\n" | |
59 |
|
59 | |||
60 | - Modify each line of a commit description:: |
|
60 | - Modify each line of a commit description:: | |
61 |
|
61 | |||
62 | $ hg log --template "{splitlines(desc) % '**** {line}\n'}" |
|
62 | $ hg log --template "{splitlines(desc) % '**** {line}\n'}" | |
63 |
|
63 | |||
64 | - Format date:: |
|
64 | - Format date:: | |
65 |
|
65 | |||
66 | $ hg log -r 0 --template "{date(date, '%Y')}\n" |
|
66 | $ hg log -r 0 --template "{date(date, '%Y')}\n" | |
67 |
|
67 | |||
68 | - Output the description set to a fill-width of 30:: |
|
68 | - Output the description set to a fill-width of 30:: | |
69 |
|
69 | |||
70 |
$ hg log -r 0 --template "{fill(desc, |
|
70 | $ hg log -r 0 --template "{fill(desc, 30)}" | |
71 |
|
71 | |||
72 | - Use a conditional to test for the default branch:: |
|
72 | - Use a conditional to test for the default branch:: | |
73 |
|
73 | |||
74 | $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch', |
|
74 | $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch', | |
75 | 'on branch {branch}')}\n" |
|
75 | 'on branch {branch}')}\n" | |
76 |
|
76 | |||
77 | - Append a newline if not empty:: |
|
77 | - Append a newline if not empty:: | |
78 |
|
78 | |||
79 | $ hg tip --template "{if(author, '{author}\n')}" |
|
79 | $ hg tip --template "{if(author, '{author}\n')}" | |
80 |
|
80 | |||
81 | - Label the output for use with the color extension:: |
|
81 | - Label the output for use with the color extension:: | |
82 |
|
82 | |||
83 | $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n" |
|
83 | $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n" | |
84 |
|
84 | |||
85 | - Invert the firstline filter, i.e. everything but the first line:: |
|
85 | - Invert the firstline filter, i.e. everything but the first line:: | |
86 |
|
86 | |||
87 | $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n" |
|
87 | $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n" | |
88 |
|
88 | |||
89 | - Display the contents of the 'extra' field, one per line:: |
|
89 | - Display the contents of the 'extra' field, one per line:: | |
90 |
|
90 | |||
91 | $ hg log -r 0 --template "{join(extras, '\n')}\n" |
|
91 | $ hg log -r 0 --template "{join(extras, '\n')}\n" | |
92 |
|
92 | |||
93 | - Mark the current bookmark with '*':: |
|
93 | - Mark the current bookmark with '*':: | |
94 |
|
94 | |||
95 | $ hg log --template "{bookmarks % '{bookmark}{ifeq(bookmark, current, \"*\")} '}\n" |
|
95 | $ hg log --template "{bookmarks % '{bookmark}{ifeq(bookmark, current, \"*\")} '}\n" | |
96 |
|
96 | |||
97 | - Mark the working copy parent with '@':: |
|
97 | - Mark the working copy parent with '@':: | |
98 |
|
98 | |||
99 | $ hg log --template "{ifcontains(rev, revset('.'), '@')}\n" |
|
99 | $ hg log --template "{ifcontains(rev, revset('.'), '@')}\n" | |
100 |
|
100 | |||
101 | - Show only commit descriptions that start with "template":: |
|
101 | - Show only commit descriptions that start with "template":: | |
102 |
|
102 | |||
103 | $ hg log --template "{startswith(\"template\", firstline(desc))}\n" |
|
103 | $ hg log --template "{startswith(\"template\", firstline(desc))}\n" | |
104 |
|
104 | |||
105 | - Print the first word of each line of a commit message:: |
|
105 | - Print the first word of each line of a commit message:: | |
106 |
|
106 | |||
107 |
$ hg log --template "{word( |
|
107 | $ hg log --template "{word(0, desc)}\n" |
General Comments 0
You need to be logged in to leave comments.
Login now