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