Show More
@@ -1,151 +1,153 b'' | |||||
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 from the command |
|
2 | templates. You can either pass in a template from the command | |
3 | line, via the --template option, or select an existing |
|
3 | line, via the --template option, or select an existing | |
4 | template-style (--style). |
|
4 | template-style (--style). | |
5 |
|
5 | |||
6 | You can customize output for any "log-like" command: log, |
|
6 | You can customize output for any "log-like" command: log, | |
7 | outgoing, incoming, tip, parents, heads and glog. |
|
7 | outgoing, incoming, tip, parents, heads and glog. | |
8 |
|
8 | |||
9 | Four styles are packaged with Mercurial: default (the style used |
|
9 | Four styles are packaged with Mercurial: default (the style used | |
10 | when no explicit preference is passed), compact, changelog, |
|
10 | when no explicit preference is passed), compact, changelog, | |
11 | and xml. |
|
11 | and xml. | |
12 | Usage:: |
|
12 | Usage:: | |
13 |
|
13 | |||
14 | $ hg log -r1 --style changelog |
|
14 | $ hg log -r1 --style changelog | |
15 |
|
15 | |||
16 | A template is a piece of text, with markup to invoke variable |
|
16 | A template is a piece of text, with markup to invoke variable | |
17 | expansion:: |
|
17 | expansion:: | |
18 |
|
18 | |||
19 | $ hg log -r1 --template "{node}\n" |
|
19 | $ hg log -r1 --template "{node}\n" | |
20 | b56ce7b07c52de7d5fd79fb89701ea538af65746 |
|
20 | b56ce7b07c52de7d5fd79fb89701ea538af65746 | |
21 |
|
21 | |||
22 | Strings in curly braces are called keywords. The availability of |
|
22 | Strings in curly braces are called keywords. The availability of | |
23 | keywords depends on the exact context of the templater. These |
|
23 | keywords depends on the exact context of the templater. These | |
24 | keywords are usually available for templating a log-like command: |
|
24 | keywords are usually available for templating a log-like command: | |
25 |
|
25 | |||
26 | :author: String. The unmodified author of the changeset. |
|
26 | :author: String. The unmodified author of the changeset. | |
27 |
|
27 | |||
28 | :branches: String. The name of the branch on which the changeset was |
|
28 | :branches: String. The name of the branch on which the changeset was | |
29 | committed. Will be empty if the branch name was default. |
|
29 | committed. Will be empty if the branch name was default. | |
30 |
|
30 | |||
|
31 | :children: List of strings. The children of the changeset. | |||
|
32 | ||||
31 | :date: Date information. The date when the changeset was committed. |
|
33 | :date: Date information. The date when the changeset was committed. | |
32 |
|
34 | |||
33 | :desc: String. The text of the changeset description. |
|
35 | :desc: String. The text of the changeset description. | |
34 |
|
36 | |||
35 | :diffstat: String. Statistics of changes with the following format: |
|
37 | :diffstat: String. Statistics of changes with the following format: | |
36 | "modified files: +added/-removed lines" |
|
38 | "modified files: +added/-removed lines" | |
37 |
|
39 | |||
38 | :files: List of strings. All files modified, added, or removed by this |
|
40 | :files: List of strings. All files modified, added, or removed by this | |
39 | changeset. |
|
41 | changeset. | |
40 |
|
42 | |||
41 | :file_adds: List of strings. Files added by this changeset. |
|
43 | :file_adds: List of strings. Files added by this changeset. | |
42 |
|
44 | |||
43 | :file_copies: List of strings. Files copied in this changeset with |
|
45 | :file_copies: List of strings. Files copied in this changeset with | |
44 | their sources. |
|
46 | their sources. | |
45 |
|
47 | |||
46 | :file_copies_switch: List of strings. Like "file_copies" but displayed |
|
48 | :file_copies_switch: List of strings. Like "file_copies" but displayed | |
47 | only if the --copied switch is set. |
|
49 | only if the --copied switch is set. | |
48 |
|
50 | |||
49 | :file_mods: List of strings. Files modified by this changeset. |
|
51 | :file_mods: List of strings. Files modified by this changeset. | |
50 |
|
52 | |||
51 | :file_dels: List of strings. Files removed by this changeset. |
|
53 | :file_dels: List of strings. Files removed by this changeset. | |
52 |
|
54 | |||
53 | :node: String. The changeset identification hash, as a 40-character |
|
55 | :node: String. The changeset identification hash, as a 40-character | |
54 | hexadecimal string. |
|
56 | hexadecimal string. | |
55 |
|
57 | |||
56 | :parents: List of strings. The parents of the changeset. |
|
58 | :parents: List of strings. The parents of the changeset. | |
57 |
|
59 | |||
58 | :rev: Integer. The repository-local changeset revision number. |
|
60 | :rev: Integer. The repository-local changeset revision number. | |
59 |
|
61 | |||
60 | :tags: List of strings. Any tags associated with the changeset. |
|
62 | :tags: List of strings. Any tags associated with the changeset. | |
61 |
|
63 | |||
62 | :latesttag: String. Most recent global tag in the ancestors of this |
|
64 | :latesttag: String. Most recent global tag in the ancestors of this | |
63 | changeset. |
|
65 | changeset. | |
64 |
|
66 | |||
65 | :latesttagdistance: Integer. Longest path to the latest tag. |
|
67 | :latesttagdistance: Integer. Longest path to the latest tag. | |
66 |
|
68 | |||
67 | The "date" keyword does not produce human-readable output. If you |
|
69 | The "date" keyword does not produce human-readable output. If you | |
68 | want to use a date in your output, you can use a filter to process |
|
70 | want to use a date in your output, you can use a filter to process | |
69 | it. Filters are functions which return a string based on the input |
|
71 | it. Filters are functions which return a string based on the input | |
70 | variable. Be sure to use the stringify filter first when you're |
|
72 | variable. Be sure to use the stringify filter first when you're | |
71 | applying a string-input filter to a list-like input variable. |
|
73 | applying a string-input filter to a list-like input variable. | |
72 | You can also use a chain of filters to get the desired output:: |
|
74 | You can also use a chain of filters to get the desired output:: | |
73 |
|
75 | |||
74 | $ hg tip --template "{date|isodate}\n" |
|
76 | $ hg tip --template "{date|isodate}\n" | |
75 | 2008-08-21 18:22 +0000 |
|
77 | 2008-08-21 18:22 +0000 | |
76 |
|
78 | |||
77 | List of filters: |
|
79 | List of filters: | |
78 |
|
80 | |||
79 | :addbreaks: Any text. Add an XHTML "<br />" tag before the end of |
|
81 | :addbreaks: Any text. Add an XHTML "<br />" tag before the end of | |
80 | every line except the last. |
|
82 | every line except the last. | |
81 |
|
83 | |||
82 | :age: Date. Returns a human-readable date/time difference between the |
|
84 | :age: Date. Returns a human-readable date/time difference between the | |
83 | given date/time and the current date/time. |
|
85 | given date/time and the current date/time. | |
84 |
|
86 | |||
85 | :basename: Any text. Treats the text as a path, and returns the last |
|
87 | :basename: Any text. Treats the text as a path, and returns the last | |
86 | component of the path after splitting by the path separator |
|
88 | component of the path after splitting by the path separator | |
87 | (ignoring trailing separators). For example, "foo/bar/baz" becomes |
|
89 | (ignoring trailing separators). For example, "foo/bar/baz" becomes | |
88 | "baz" and "foo/bar//" becomes "bar". |
|
90 | "baz" and "foo/bar//" becomes "bar". | |
89 |
|
91 | |||
90 | :stripdir: Treat the text as path and strip a directory level, if |
|
92 | :stripdir: Treat the text as path and strip a directory level, if | |
91 | possible. For example, "foo" and "foo/bar" becomes "foo". |
|
93 | possible. For example, "foo" and "foo/bar" becomes "foo". | |
92 |
|
94 | |||
93 | :date: Date. Returns a date in a Unix date format, including the |
|
95 | :date: Date. Returns a date in a Unix date format, including the | |
94 | timezone: "Mon Sep 04 15:13:13 2006 0700". |
|
96 | timezone: "Mon Sep 04 15:13:13 2006 0700". | |
95 |
|
97 | |||
96 | :domain: Any text. Finds the first string that looks like an email |
|
98 | :domain: Any text. Finds the first string that looks like an email | |
97 | address, and extracts just the domain component. Example: ``User |
|
99 | address, and extracts just the domain component. Example: ``User | |
98 | <user@example.com>`` becomes ``example.com``. |
|
100 | <user@example.com>`` becomes ``example.com``. | |
99 |
|
101 | |||
100 | :email: Any text. Extracts the first string that looks like an email |
|
102 | :email: Any text. Extracts the first string that looks like an email | |
101 | address. Example: ``User <user@example.com>`` becomes |
|
103 | address. Example: ``User <user@example.com>`` becomes | |
102 | ``user@example.com``. |
|
104 | ``user@example.com``. | |
103 |
|
105 | |||
104 | :escape: Any text. Replaces the special XML/XHTML characters "&", "<" |
|
106 | :escape: Any text. Replaces the special XML/XHTML characters "&", "<" | |
105 | and ">" with XML entities. |
|
107 | and ">" with XML entities. | |
106 |
|
108 | |||
107 | :fill68: Any text. Wraps the text to fit in 68 columns. |
|
109 | :fill68: Any text. Wraps the text to fit in 68 columns. | |
108 |
|
110 | |||
109 | :fill76: Any text. Wraps the text to fit in 76 columns. |
|
111 | :fill76: Any text. Wraps the text to fit in 76 columns. | |
110 |
|
112 | |||
111 | :firstline: Any text. Returns the first line of text. |
|
113 | :firstline: Any text. Returns the first line of text. | |
112 |
|
114 | |||
113 | :nonempty: Any text. Returns '(none)' if the string is empty. |
|
115 | :nonempty: Any text. Returns '(none)' if the string is empty. | |
114 |
|
116 | |||
115 | :hgdate: Date. Returns the date as a pair of numbers: "1157407993 |
|
117 | :hgdate: Date. Returns the date as a pair of numbers: "1157407993 | |
116 | 25200" (Unix timestamp, timezone offset). |
|
118 | 25200" (Unix timestamp, timezone offset). | |
117 |
|
119 | |||
118 | :isodate: Date. Returns the date in ISO 8601 format: "2009-08-18 13:00 |
|
120 | :isodate: Date. Returns the date in ISO 8601 format: "2009-08-18 13:00 | |
119 | +0200". |
|
121 | +0200". | |
120 |
|
122 | |||
121 | :isodatesec: Date. Returns the date in ISO 8601 format, including |
|
123 | :isodatesec: Date. Returns the date in ISO 8601 format, including | |
122 | seconds: "2009-08-18 13:00:13 +0200". See also the rfc3339date |
|
124 | seconds: "2009-08-18 13:00:13 +0200". See also the rfc3339date | |
123 | filter. |
|
125 | filter. | |
124 |
|
126 | |||
125 | :localdate: Date. Converts a date to local date. |
|
127 | :localdate: Date. Converts a date to local date. | |
126 |
|
128 | |||
127 | :obfuscate: Any text. Returns the input text rendered as a sequence of |
|
129 | :obfuscate: Any text. Returns the input text rendered as a sequence of | |
128 | XML entities. |
|
130 | XML entities. | |
129 |
|
131 | |||
130 | :person: Any text. Returns the text before an email address. |
|
132 | :person: Any text. Returns the text before an email address. | |
131 |
|
133 | |||
132 | :rfc822date: Date. Returns a date using the same format used in email |
|
134 | :rfc822date: Date. Returns a date using the same format used in email | |
133 | headers: "Tue, 18 Aug 2009 13:00:13 +0200". |
|
135 | headers: "Tue, 18 Aug 2009 13:00:13 +0200". | |
134 |
|
136 | |||
135 | :rfc3339date: Date. Returns a date using the Internet date format |
|
137 | :rfc3339date: Date. Returns a date using the Internet date format | |
136 | specified in RFC 3339: "2009-08-18T13:00:13+02:00". |
|
138 | specified in RFC 3339: "2009-08-18T13:00:13+02:00". | |
137 |
|
139 | |||
138 | :short: Changeset hash. Returns the short form of a changeset hash, |
|
140 | :short: Changeset hash. Returns the short form of a changeset hash, | |
139 | i.e. a 12-byte hexadecimal string. |
|
141 | i.e. a 12-byte hexadecimal string. | |
140 |
|
142 | |||
141 | :shortdate: Date. Returns a date like "2006-09-18". |
|
143 | :shortdate: Date. Returns a date like "2006-09-18". | |
142 |
|
144 | |||
143 | :strip: Any text. Strips all leading and trailing whitespace. |
|
145 | :strip: Any text. Strips all leading and trailing whitespace. | |
144 |
|
146 | |||
145 | :tabindent: Any text. Returns the text, with every line except the |
|
147 | :tabindent: Any text. Returns the text, with every line except the | |
146 | first starting with a tab character. |
|
148 | first starting with a tab character. | |
147 |
|
149 | |||
148 | :urlescape: Any text. Escapes all "special" characters. For example, |
|
150 | :urlescape: Any text. Escapes all "special" characters. For example, | |
149 | "foo bar" becomes "foo%20bar". |
|
151 | "foo bar" becomes "foo%20bar". | |
150 |
|
152 | |||
151 | :user: Any text. Returns the user portion of an email address. |
|
153 | :user: Any text. Returns the user portion of an email address. |
@@ -1,265 +1,271 b'' | |||||
1 | # templatekw.py - common changeset template keywords |
|
1 | # templatekw.py - common changeset template keywords | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from node import hex |
|
8 | from node import hex | |
9 | import encoding, patch, util, error |
|
9 | import encoding, patch, util, error | |
10 |
|
10 | |||
11 | def showlist(name, values, plural=None, **args): |
|
11 | def showlist(name, values, plural=None, **args): | |
12 | '''expand set of values. |
|
12 | '''expand set of values. | |
13 | name is name of key in template map. |
|
13 | name is name of key in template map. | |
14 | values is list of strings or dicts. |
|
14 | values is list of strings or dicts. | |
15 | plural is plural of name, if not simply name + 's'. |
|
15 | plural is plural of name, if not simply name + 's'. | |
16 |
|
16 | |||
17 | expansion works like this, given name 'foo'. |
|
17 | expansion works like this, given name 'foo'. | |
18 |
|
18 | |||
19 | if values is empty, expand 'no_foos'. |
|
19 | if values is empty, expand 'no_foos'. | |
20 |
|
20 | |||
21 | if 'foo' not in template map, return values as a string, |
|
21 | if 'foo' not in template map, return values as a string, | |
22 | joined by space. |
|
22 | joined by space. | |
23 |
|
23 | |||
24 | expand 'start_foos'. |
|
24 | expand 'start_foos'. | |
25 |
|
25 | |||
26 | for each value, expand 'foo'. if 'last_foo' in template |
|
26 | for each value, expand 'foo'. if 'last_foo' in template | |
27 | map, expand it instead of 'foo' for last key. |
|
27 | map, expand it instead of 'foo' for last key. | |
28 |
|
28 | |||
29 | expand 'end_foos'. |
|
29 | expand 'end_foos'. | |
30 | ''' |
|
30 | ''' | |
31 | templ = args['templ'] |
|
31 | templ = args['templ'] | |
32 | if plural: |
|
32 | if plural: | |
33 | names = plural |
|
33 | names = plural | |
34 | else: names = name + 's' |
|
34 | else: names = name + 's' | |
35 | if not values: |
|
35 | if not values: | |
36 | noname = 'no_' + names |
|
36 | noname = 'no_' + names | |
37 | if noname in templ: |
|
37 | if noname in templ: | |
38 | yield templ(noname, **args) |
|
38 | yield templ(noname, **args) | |
39 | return |
|
39 | return | |
40 | if name not in templ: |
|
40 | if name not in templ: | |
41 | if isinstance(values[0], str): |
|
41 | if isinstance(values[0], str): | |
42 | yield ' '.join(values) |
|
42 | yield ' '.join(values) | |
43 | else: |
|
43 | else: | |
44 | for v in values: |
|
44 | for v in values: | |
45 | yield dict(v, **args) |
|
45 | yield dict(v, **args) | |
46 | return |
|
46 | return | |
47 | startname = 'start_' + names |
|
47 | startname = 'start_' + names | |
48 | if startname in templ: |
|
48 | if startname in templ: | |
49 | yield templ(startname, **args) |
|
49 | yield templ(startname, **args) | |
50 | vargs = args.copy() |
|
50 | vargs = args.copy() | |
51 | def one(v, tag=name): |
|
51 | def one(v, tag=name): | |
52 | try: |
|
52 | try: | |
53 | vargs.update(v) |
|
53 | vargs.update(v) | |
54 | except (AttributeError, ValueError): |
|
54 | except (AttributeError, ValueError): | |
55 | try: |
|
55 | try: | |
56 | for a, b in v: |
|
56 | for a, b in v: | |
57 | vargs[a] = b |
|
57 | vargs[a] = b | |
58 | except ValueError: |
|
58 | except ValueError: | |
59 | vargs[name] = v |
|
59 | vargs[name] = v | |
60 | return templ(tag, **vargs) |
|
60 | return templ(tag, **vargs) | |
61 | lastname = 'last_' + name |
|
61 | lastname = 'last_' + name | |
62 | if lastname in templ: |
|
62 | if lastname in templ: | |
63 | last = values.pop() |
|
63 | last = values.pop() | |
64 | else: |
|
64 | else: | |
65 | last = None |
|
65 | last = None | |
66 | for v in values: |
|
66 | for v in values: | |
67 | yield one(v) |
|
67 | yield one(v) | |
68 | if last is not None: |
|
68 | if last is not None: | |
69 | yield one(last, tag=lastname) |
|
69 | yield one(last, tag=lastname) | |
70 | endname = 'end_' + names |
|
70 | endname = 'end_' + names | |
71 | if endname in templ: |
|
71 | if endname in templ: | |
72 | yield templ(endname, **args) |
|
72 | yield templ(endname, **args) | |
73 |
|
73 | |||
74 | def getfiles(repo, ctx, revcache): |
|
74 | def getfiles(repo, ctx, revcache): | |
75 | if 'files' not in revcache: |
|
75 | if 'files' not in revcache: | |
76 | revcache['files'] = repo.status(ctx.parents()[0].node(), |
|
76 | revcache['files'] = repo.status(ctx.parents()[0].node(), | |
77 | ctx.node())[:3] |
|
77 | ctx.node())[:3] | |
78 | return revcache['files'] |
|
78 | return revcache['files'] | |
79 |
|
79 | |||
80 | def getlatesttags(repo, ctx, cache): |
|
80 | def getlatesttags(repo, ctx, cache): | |
81 | '''return date, distance and name for the latest tag of rev''' |
|
81 | '''return date, distance and name for the latest tag of rev''' | |
82 |
|
82 | |||
83 | if 'latesttags' not in cache: |
|
83 | if 'latesttags' not in cache: | |
84 | # Cache mapping from rev to a tuple with tag date, tag |
|
84 | # Cache mapping from rev to a tuple with tag date, tag | |
85 | # distance and tag name |
|
85 | # distance and tag name | |
86 | cache['latesttags'] = {-1: (0, 0, 'null')} |
|
86 | cache['latesttags'] = {-1: (0, 0, 'null')} | |
87 | latesttags = cache['latesttags'] |
|
87 | latesttags = cache['latesttags'] | |
88 |
|
88 | |||
89 | rev = ctx.rev() |
|
89 | rev = ctx.rev() | |
90 | todo = [rev] |
|
90 | todo = [rev] | |
91 | while todo: |
|
91 | while todo: | |
92 | rev = todo.pop() |
|
92 | rev = todo.pop() | |
93 | if rev in latesttags: |
|
93 | if rev in latesttags: | |
94 | continue |
|
94 | continue | |
95 | ctx = repo[rev] |
|
95 | ctx = repo[rev] | |
96 | tags = [t for t in ctx.tags() if repo.tagtype(t) == 'global'] |
|
96 | tags = [t for t in ctx.tags() if repo.tagtype(t) == 'global'] | |
97 | if tags: |
|
97 | if tags: | |
98 | latesttags[rev] = ctx.date()[0], 0, ':'.join(sorted(tags)) |
|
98 | latesttags[rev] = ctx.date()[0], 0, ':'.join(sorted(tags)) | |
99 | continue |
|
99 | continue | |
100 | try: |
|
100 | try: | |
101 | # The tuples are laid out so the right one can be found by |
|
101 | # The tuples are laid out so the right one can be found by | |
102 | # comparison. |
|
102 | # comparison. | |
103 | pdate, pdist, ptag = max( |
|
103 | pdate, pdist, ptag = max( | |
104 | latesttags[p.rev()] for p in ctx.parents()) |
|
104 | latesttags[p.rev()] for p in ctx.parents()) | |
105 | except KeyError: |
|
105 | except KeyError: | |
106 | # Cache miss - recurse |
|
106 | # Cache miss - recurse | |
107 | todo.append(rev) |
|
107 | todo.append(rev) | |
108 | todo.extend(p.rev() for p in ctx.parents()) |
|
108 | todo.extend(p.rev() for p in ctx.parents()) | |
109 | continue |
|
109 | continue | |
110 | latesttags[rev] = pdate, pdist + 1, ptag |
|
110 | latesttags[rev] = pdate, pdist + 1, ptag | |
111 | return latesttags[rev] |
|
111 | return latesttags[rev] | |
112 |
|
112 | |||
113 | def getrenamedfn(repo, endrev=None): |
|
113 | def getrenamedfn(repo, endrev=None): | |
114 | rcache = {} |
|
114 | rcache = {} | |
115 | if endrev is None: |
|
115 | if endrev is None: | |
116 | endrev = len(repo) |
|
116 | endrev = len(repo) | |
117 |
|
117 | |||
118 | def getrenamed(fn, rev): |
|
118 | def getrenamed(fn, rev): | |
119 | '''looks up all renames for a file (up to endrev) the first |
|
119 | '''looks up all renames for a file (up to endrev) the first | |
120 | time the file is given. It indexes on the changerev and only |
|
120 | time the file is given. It indexes on the changerev and only | |
121 | parses the manifest if linkrev != changerev. |
|
121 | parses the manifest if linkrev != changerev. | |
122 | Returns rename info for fn at changerev rev.''' |
|
122 | Returns rename info for fn at changerev rev.''' | |
123 | if fn not in rcache: |
|
123 | if fn not in rcache: | |
124 | rcache[fn] = {} |
|
124 | rcache[fn] = {} | |
125 | fl = repo.file(fn) |
|
125 | fl = repo.file(fn) | |
126 | for i in fl: |
|
126 | for i in fl: | |
127 | lr = fl.linkrev(i) |
|
127 | lr = fl.linkrev(i) | |
128 | renamed = fl.renamed(fl.node(i)) |
|
128 | renamed = fl.renamed(fl.node(i)) | |
129 | rcache[fn][lr] = renamed |
|
129 | rcache[fn][lr] = renamed | |
130 | if lr >= endrev: |
|
130 | if lr >= endrev: | |
131 | break |
|
131 | break | |
132 | if rev in rcache[fn]: |
|
132 | if rev in rcache[fn]: | |
133 | return rcache[fn][rev] |
|
133 | return rcache[fn][rev] | |
134 |
|
134 | |||
135 | # If linkrev != rev (i.e. rev not found in rcache) fallback to |
|
135 | # If linkrev != rev (i.e. rev not found in rcache) fallback to | |
136 | # filectx logic. |
|
136 | # filectx logic. | |
137 | try: |
|
137 | try: | |
138 | return repo[rev][fn].renamed() |
|
138 | return repo[rev][fn].renamed() | |
139 | except error.LookupError: |
|
139 | except error.LookupError: | |
140 | return None |
|
140 | return None | |
141 |
|
141 | |||
142 | return getrenamed |
|
142 | return getrenamed | |
143 |
|
143 | |||
144 |
|
144 | |||
145 | def showauthor(repo, ctx, templ, **args): |
|
145 | def showauthor(repo, ctx, templ, **args): | |
146 | return ctx.user() |
|
146 | return ctx.user() | |
147 |
|
147 | |||
148 | def showbranches(**args): |
|
148 | def showbranches(**args): | |
149 | branch = args['ctx'].branch() |
|
149 | branch = args['ctx'].branch() | |
150 | if branch != 'default': |
|
150 | if branch != 'default': | |
151 | branch = encoding.tolocal(branch) |
|
151 | branch = encoding.tolocal(branch) | |
152 | return showlist('branch', [branch], plural='branches', **args) |
|
152 | return showlist('branch', [branch], plural='branches', **args) | |
153 |
|
153 | |||
|
154 | def showchildren(**args): | |||
|
155 | ctx = args['ctx'] | |||
|
156 | childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()] | |||
|
157 | return showlist('children', childrevs, **args) | |||
|
158 | ||||
154 | def showdate(repo, ctx, templ, **args): |
|
159 | def showdate(repo, ctx, templ, **args): | |
155 | return ctx.date() |
|
160 | return ctx.date() | |
156 |
|
161 | |||
157 | def showdescription(repo, ctx, templ, **args): |
|
162 | def showdescription(repo, ctx, templ, **args): | |
158 | return ctx.description().strip() |
|
163 | return ctx.description().strip() | |
159 |
|
164 | |||
160 | def showdiffstat(repo, ctx, templ, **args): |
|
165 | def showdiffstat(repo, ctx, templ, **args): | |
161 | diff = patch.diff(repo, ctx.parents()[0].node(), ctx.node()) |
|
166 | diff = patch.diff(repo, ctx.parents()[0].node(), ctx.node()) | |
162 | files, adds, removes = 0, 0, 0 |
|
167 | files, adds, removes = 0, 0, 0 | |
163 | for i in patch.diffstatdata(util.iterlines(diff)): |
|
168 | for i in patch.diffstatdata(util.iterlines(diff)): | |
164 | files += 1 |
|
169 | files += 1 | |
165 | adds += i[1] |
|
170 | adds += i[1] | |
166 | removes += i[2] |
|
171 | removes += i[2] | |
167 | return '%s: +%s/-%s' % (files, adds, removes) |
|
172 | return '%s: +%s/-%s' % (files, adds, removes) | |
168 |
|
173 | |||
169 | def showextras(**args): |
|
174 | def showextras(**args): | |
170 | templ = args['templ'] |
|
175 | templ = args['templ'] | |
171 | for key, value in sorted(args['ctx'].extra().items()): |
|
176 | for key, value in sorted(args['ctx'].extra().items()): | |
172 | args = args.copy() |
|
177 | args = args.copy() | |
173 | args.update(dict(key=key, value=value)) |
|
178 | args.update(dict(key=key, value=value)) | |
174 | yield templ('extra', **args) |
|
179 | yield templ('extra', **args) | |
175 |
|
180 | |||
176 | def showfileadds(**args): |
|
181 | def showfileadds(**args): | |
177 | repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
|
182 | repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] | |
178 | return showlist('file_add', getfiles(repo, ctx, revcache)[1], **args) |
|
183 | return showlist('file_add', getfiles(repo, ctx, revcache)[1], **args) | |
179 |
|
184 | |||
180 | def showfilecopies(**args): |
|
185 | def showfilecopies(**args): | |
181 | cache, ctx = args['cache'], args['ctx'] |
|
186 | cache, ctx = args['cache'], args['ctx'] | |
182 | copies = args['revcache'].get('copies') |
|
187 | copies = args['revcache'].get('copies') | |
183 | if copies is None: |
|
188 | if copies is None: | |
184 | if 'getrenamed' not in cache: |
|
189 | if 'getrenamed' not in cache: | |
185 | cache['getrenamed'] = getrenamedfn(args['repo']) |
|
190 | cache['getrenamed'] = getrenamedfn(args['repo']) | |
186 | copies = [] |
|
191 | copies = [] | |
187 | getrenamed = cache['getrenamed'] |
|
192 | getrenamed = cache['getrenamed'] | |
188 | for fn in ctx.files(): |
|
193 | for fn in ctx.files(): | |
189 | rename = getrenamed(fn, ctx.rev()) |
|
194 | rename = getrenamed(fn, ctx.rev()) | |
190 | if rename: |
|
195 | if rename: | |
191 | copies.append((fn, rename[0])) |
|
196 | copies.append((fn, rename[0])) | |
192 |
|
197 | |||
193 | c = [{'name': x[0], 'source': x[1]} for x in copies] |
|
198 | c = [{'name': x[0], 'source': x[1]} for x in copies] | |
194 | return showlist('file_copy', c, plural='file_copies', **args) |
|
199 | return showlist('file_copy', c, plural='file_copies', **args) | |
195 |
|
200 | |||
196 | # showfilecopiesswitch() displays file copies only if copy records are |
|
201 | # showfilecopiesswitch() displays file copies only if copy records are | |
197 | # provided before calling the templater, usually with a --copies |
|
202 | # provided before calling the templater, usually with a --copies | |
198 | # command line switch. |
|
203 | # command line switch. | |
199 | def showfilecopiesswitch(**args): |
|
204 | def showfilecopiesswitch(**args): | |
200 | copies = args['revcache'].get('copies') or [] |
|
205 | copies = args['revcache'].get('copies') or [] | |
201 | c = [{'name': x[0], 'source': x[1]} for x in copies] |
|
206 | c = [{'name': x[0], 'source': x[1]} for x in copies] | |
202 | return showlist('file_copy', c, plural='file_copies', **args) |
|
207 | return showlist('file_copy', c, plural='file_copies', **args) | |
203 |
|
208 | |||
204 | def showfiledels(**args): |
|
209 | def showfiledels(**args): | |
205 | repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
|
210 | repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] | |
206 | return showlist('file_del', getfiles(repo, ctx, revcache)[2], **args) |
|
211 | return showlist('file_del', getfiles(repo, ctx, revcache)[2], **args) | |
207 |
|
212 | |||
208 | def showfilemods(**args): |
|
213 | def showfilemods(**args): | |
209 | repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
|
214 | repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] | |
210 | return showlist('file_mod', getfiles(repo, ctx, revcache)[0], **args) |
|
215 | return showlist('file_mod', getfiles(repo, ctx, revcache)[0], **args) | |
211 |
|
216 | |||
212 | def showfiles(**args): |
|
217 | def showfiles(**args): | |
213 | return showlist('file', args['ctx'].files(), **args) |
|
218 | return showlist('file', args['ctx'].files(), **args) | |
214 |
|
219 | |||
215 | def showlatesttag(repo, ctx, templ, cache, **args): |
|
220 | def showlatesttag(repo, ctx, templ, cache, **args): | |
216 | return getlatesttags(repo, ctx, cache)[2] |
|
221 | return getlatesttags(repo, ctx, cache)[2] | |
217 |
|
222 | |||
218 | def showlatesttagdistance(repo, ctx, templ, cache, **args): |
|
223 | def showlatesttagdistance(repo, ctx, templ, cache, **args): | |
219 | return getlatesttags(repo, ctx, cache)[1] |
|
224 | return getlatesttags(repo, ctx, cache)[1] | |
220 |
|
225 | |||
221 | def showmanifest(**args): |
|
226 | def showmanifest(**args): | |
222 | repo, ctx, templ = args['repo'], args['ctx'], args['templ'] |
|
227 | repo, ctx, templ = args['repo'], args['ctx'], args['templ'] | |
223 | args = args.copy() |
|
228 | args = args.copy() | |
224 | args.update(dict(rev=repo.manifest.rev(ctx.changeset()[0]), |
|
229 | args.update(dict(rev=repo.manifest.rev(ctx.changeset()[0]), | |
225 | node=hex(ctx.changeset()[0]))) |
|
230 | node=hex(ctx.changeset()[0]))) | |
226 | return templ('manifest', **args) |
|
231 | return templ('manifest', **args) | |
227 |
|
232 | |||
228 | def shownode(repo, ctx, templ, **args): |
|
233 | def shownode(repo, ctx, templ, **args): | |
229 | return ctx.hex() |
|
234 | return ctx.hex() | |
230 |
|
235 | |||
231 | def showrev(repo, ctx, templ, **args): |
|
236 | def showrev(repo, ctx, templ, **args): | |
232 | return ctx.rev() |
|
237 | return ctx.rev() | |
233 |
|
238 | |||
234 | def showtags(**args): |
|
239 | def showtags(**args): | |
235 | return showlist('tag', args['ctx'].tags(), **args) |
|
240 | return showlist('tag', args['ctx'].tags(), **args) | |
236 |
|
241 | |||
237 | # keywords are callables like: |
|
242 | # keywords are callables like: | |
238 | # fn(repo, ctx, templ, cache, revcache, **args) |
|
243 | # fn(repo, ctx, templ, cache, revcache, **args) | |
239 | # with: |
|
244 | # with: | |
240 | # repo - current repository instance |
|
245 | # repo - current repository instance | |
241 | # ctx - the changectx being displayed |
|
246 | # ctx - the changectx being displayed | |
242 | # templ - the templater instance |
|
247 | # templ - the templater instance | |
243 | # cache - a cache dictionary for the whole templater run |
|
248 | # cache - a cache dictionary for the whole templater run | |
244 | # revcache - a cache dictionary for the current revision |
|
249 | # revcache - a cache dictionary for the current revision | |
245 | keywords = { |
|
250 | keywords = { | |
246 | 'author': showauthor, |
|
251 | 'author': showauthor, | |
247 | 'branches': showbranches, |
|
252 | 'branches': showbranches, | |
|
253 | 'children': showchildren, | |||
248 | 'date': showdate, |
|
254 | 'date': showdate, | |
249 | 'desc': showdescription, |
|
255 | 'desc': showdescription, | |
250 | 'diffstat': showdiffstat, |
|
256 | 'diffstat': showdiffstat, | |
251 | 'extras': showextras, |
|
257 | 'extras': showextras, | |
252 | 'file_adds': showfileadds, |
|
258 | 'file_adds': showfileadds, | |
253 | 'file_copies': showfilecopies, |
|
259 | 'file_copies': showfilecopies, | |
254 | 'file_copies_switch': showfilecopiesswitch, |
|
260 | 'file_copies_switch': showfilecopiesswitch, | |
255 | 'file_dels': showfiledels, |
|
261 | 'file_dels': showfiledels, | |
256 | 'file_mods': showfilemods, |
|
262 | 'file_mods': showfilemods, | |
257 | 'files': showfiles, |
|
263 | 'files': showfiles, | |
258 | 'latesttag': showlatesttag, |
|
264 | 'latesttag': showlatesttag, | |
259 | 'latesttagdistance': showlatesttagdistance, |
|
265 | 'latesttagdistance': showlatesttagdistance, | |
260 | 'manifest': showmanifest, |
|
266 | 'manifest': showmanifest, | |
261 | 'node': shownode, |
|
267 | 'node': shownode, | |
262 | 'rev': showrev, |
|
268 | 'rev': showrev, | |
263 | 'tags': showtags, |
|
269 | 'tags': showtags, | |
264 | } |
|
270 | } | |
265 |
|
271 |
General Comments 0
You need to be logged in to leave comments.
Login now