annotate mercurial/templatekw.py @ 32928:498e9dcc5fa9

templatekw: populate all keywords depending on predecessor in map operation This is what showparents() does. repo[precnode] should never fail since its validity is tested by closestpredecessors().
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Jun 2017 13:23:55 +0900
parents 89610c586fa2
children 7f1d07d2c8f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
1 # templatekw.py - common changeset template keywords
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
2 #
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com>
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
4 #
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
10264
d6512b3e9ac0 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 10260
diff changeset
6 # GNU General Public License version 2 or any later version.
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
7
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
8 from __future__ import absolute_import
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
9
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
10 from .i18n import _
32678
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
11 from .node import (
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
12 hex,
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
13 nullid,
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
14 short,
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
15 )
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
16
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
17 from . import (
28239
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
18 encoding,
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
19 error,
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
20 hbisect,
32897
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
21 obsutil,
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
22 patch,
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
23 registrar,
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
24 scmutil,
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
25 util,
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
26 )
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
27
31879
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
28 class _hybrid(object):
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
29 """Wrapper for list or dict to support legacy template
17631
0b241d7a8c62 templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents: 17358
diff changeset
30
31879
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
31 This class allows us to handle both:
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
32 - "{files}" (legacy command-line-specific list hack) and
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
33 - "{files % '{file}\n'}" (hgweb-style with inlining and function support)
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
34 and to access raw values:
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
35 - "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}"
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
36 - "{get(extras, key)}"
31882
ba5b74f780d5 templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents: 31881
diff changeset
37 - "{files|json}"
31879
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
38 """
868ec199cad0 templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents: 31850
diff changeset
39
29683
bdc81970853d templatekw: change joinfmt to a mandatory argument of _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 29624
diff changeset
40 def __init__(self, gen, values, makemap, joinfmt):
31923
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
41 if gen is not None:
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
42 self.gen = gen
31881
31dad7a5b4ed templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents: 31880
diff changeset
43 self._values = values
24239
31f9b1b16d1e templatekw: keep raw list or dict in _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 24238
diff changeset
44 self._makemap = makemap
29683
bdc81970853d templatekw: change joinfmt to a mandatory argument of _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 29624
diff changeset
45 self.joinfmt = joinfmt
31923
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
46 @util.propertycache
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
47 def gen(self):
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
48 return self._defaultgen()
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
49 def _defaultgen(self):
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
50 """Generator to stringify this as {join(self, ' ')}"""
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
51 for i, d in enumerate(self.itermaps()):
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
52 if i > 0:
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
53 yield ' '
68c910fa9ee2 templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents: 31882
diff changeset
54 yield self.joinfmt(d)
27891
ac8c0ee5c3b8 templater: make _hybrid not callable to avoid conflicting semantics
Yuya Nishihara <yuya@tcha.org>
parents: 27215
diff changeset
55 def itermaps(self):
24239
31f9b1b16d1e templatekw: keep raw list or dict in _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 24238
diff changeset
56 makemap = self._makemap
31881
31dad7a5b4ed templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents: 31880
diff changeset
57 for x in self._values:
24239
31f9b1b16d1e templatekw: keep raw list or dict in _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 24238
diff changeset
58 yield makemap(x)
24240
bd504d90588d templater: implement _hybrid.__contains__ so that ifcontains can accept dict
Yuya Nishihara <yuya@tcha.org>
parents: 24239
diff changeset
59 def __contains__(self, x):
31881
31dad7a5b4ed templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents: 31880
diff changeset
60 return x in self._values
22393
293930a1fa0a templater: implement __len__ for _hybrid
Anton Shestakov <engored@ya.ru>
parents: 21897
diff changeset
61 def __len__(self):
31881
31dad7a5b4ed templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents: 31880
diff changeset
62 return len(self._values)
31882
ba5b74f780d5 templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents: 31881
diff changeset
63 def __iter__(self):
ba5b74f780d5 templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents: 31881
diff changeset
64 return iter(self._values)
24241
e7baf88c29c3 templatekw: forward _hybrid.get to raw values so that get(extras, key) works
Yuya Nishihara <yuya@tcha.org>
parents: 24240
diff changeset
65 def __getattr__(self, name):
31882
ba5b74f780d5 templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents: 31881
diff changeset
66 if name not in ('get', 'items', 'iteritems', 'iterkeys', 'itervalues',
ba5b74f780d5 templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents: 31881
diff changeset
67 'keys', 'values'):
24241
e7baf88c29c3 templatekw: forward _hybrid.get to raw values so that get(extras, key) works
Yuya Nishihara <yuya@tcha.org>
parents: 24240
diff changeset
68 raise AttributeError(name)
31881
31dad7a5b4ed templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents: 31880
diff changeset
69 return getattr(self._values, name)
17631
0b241d7a8c62 templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents: 17358
diff changeset
70
31925
5b2241e84982 templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31924
diff changeset
71 def hybriddict(data, key='key', value='value', fmt='%s=%s', gen=None):
5b2241e84982 templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31924
diff changeset
72 """Wrap data to support both dict-like and string-like operations"""
5b2241e84982 templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31924
diff changeset
73 return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
5b2241e84982 templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31924
diff changeset
74 lambda d: fmt % (d[key], d[value]))
5b2241e84982 templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31924
diff changeset
75
31924
21f129354dd0 templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31923
diff changeset
76 def hybridlist(data, name, fmt='%s', gen=None):
21f129354dd0 templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31923
diff changeset
77 """Wrap data to support both list-like and string-like operations"""
21f129354dd0 templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31923
diff changeset
78 return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name])
21f129354dd0 templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31923
diff changeset
79
31880
a0f2d83f8083 templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents: 31879
diff changeset
80 def unwraphybrid(thing):
a0f2d83f8083 templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents: 31879
diff changeset
81 """Return an object which can be stringified possibly by using a legacy
a0f2d83f8083 templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents: 31879
diff changeset
82 template"""
a0f2d83f8083 templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents: 31879
diff changeset
83 if not util.safehasattr(thing, 'gen'):
a0f2d83f8083 templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents: 31879
diff changeset
84 return thing
a0f2d83f8083 templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents: 31879
diff changeset
85 return thing.gen
a0f2d83f8083 templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents: 31879
diff changeset
86
32038
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
87 def showdict(name, data, mapping, plural=None, key='key', value='value',
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
88 fmt='%s=%s', separator=' '):
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
89 c = [{key: k, value: v} for k, v in data.iteritems()]
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
90 f = _showlist(name, c, mapping, plural, separator)
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
91 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
92
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
93 def showlist(name, values, mapping, plural=None, element=None, separator=' '):
17631
0b241d7a8c62 templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents: 17358
diff changeset
94 if not element:
0b241d7a8c62 templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents: 17358
diff changeset
95 element = name
32036
8bcc8c9b4e9f templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents: 32035
diff changeset
96 f = _showlist(name, values, mapping, plural, separator)
31924
21f129354dd0 templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 31923
diff changeset
97 return hybridlist(values, name=element, gen=f)
17631
0b241d7a8c62 templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents: 17358
diff changeset
98
32036
8bcc8c9b4e9f templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents: 32035
diff changeset
99 def _showlist(name, values, mapping, plural=None, separator=' '):
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
100 '''expand set of values.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
101 name is name of key in template map.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
102 values is list of strings or dicts.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
103 plural is plural of name, if not simply name + 's'.
25726
b44e483726d3 templatekw: allow the caller of showlist() to specify the join() separator
Matt Harbison <matt_harbison@yahoo.com>
parents: 25724
diff changeset
104 separator is used to join values as a string
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
105
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
106 expansion works like this, given name 'foo'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
107
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
108 if values is empty, expand 'no_foos'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
109
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
110 if 'foo' not in template map, return values as a string,
25726
b44e483726d3 templatekw: allow the caller of showlist() to specify the join() separator
Matt Harbison <matt_harbison@yahoo.com>
parents: 25724
diff changeset
111 joined by 'separator'.
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
112
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
113 expand 'start_foos'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
114
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
115 for each value, expand 'foo'. if 'last_foo' in template
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
116 map, expand it instead of 'foo' for last key.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
117
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
118 expand 'end_foos'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
119 '''
32035
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
120 templ = mapping['templ']
32034
579bbcb4322b templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 31925
diff changeset
121 if not plural:
579bbcb4322b templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 31925
diff changeset
122 plural = name + 's'
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
123 if not values:
32034
579bbcb4322b templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 31925
diff changeset
124 noname = 'no_' + plural
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
125 if noname in templ:
32035
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
126 yield templ(noname, **mapping)
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
127 return
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
128 if name not in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
129 if isinstance(values[0], str):
25726
b44e483726d3 templatekw: allow the caller of showlist() to specify the join() separator
Matt Harbison <matt_harbison@yahoo.com>
parents: 25724
diff changeset
130 yield separator.join(values)
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
131 else:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
132 for v in values:
32035
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
133 yield dict(v, **mapping)
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
134 return
32034
579bbcb4322b templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 31925
diff changeset
135 startname = 'start_' + plural
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
136 if startname in templ:
32035
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
137 yield templ(startname, **mapping)
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
138 vmapping = mapping.copy()
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
139 def one(v, tag=name):
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
140 try:
32035
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
141 vmapping.update(v)
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
142 except (AttributeError, ValueError):
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
143 try:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
144 for a, b in v:
32035
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
145 vmapping[a] = b
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
146 except ValueError:
32035
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
147 vmapping[name] = v
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
148 return templ(tag, **vmapping)
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
149 lastname = 'last_' + name
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
150 if lastname in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
151 last = values.pop()
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
152 else:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
153 last = None
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
154 for v in values:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
155 yield one(v)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
156 if last is not None:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
157 yield one(last, tag=lastname)
32034
579bbcb4322b templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 31925
diff changeset
158 endname = 'end_' + plural
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
159 if endname in templ:
32035
f4ba33454b28 templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 32034
diff changeset
160 yield templ(endname, **mapping)
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
161
29624
1a129dd05b7d templatekw: fix join format of parents keyword (issue5292)
Yuya Nishihara <yuya@tcha.org>
parents: 29623
diff changeset
162 def _formatrevnode(ctx):
1a129dd05b7d templatekw: fix join format of parents keyword (issue5292)
Yuya Nishihara <yuya@tcha.org>
parents: 29623
diff changeset
163 """Format changeset as '{rev}:{node|formatnode}', which is the default
1a129dd05b7d templatekw: fix join format of parents keyword (issue5292)
Yuya Nishihara <yuya@tcha.org>
parents: 29623
diff changeset
164 template provided by cmdutil.changeset_templater"""
1a129dd05b7d templatekw: fix join format of parents keyword (issue5292)
Yuya Nishihara <yuya@tcha.org>
parents: 29623
diff changeset
165 repo = ctx.repo()
1a129dd05b7d templatekw: fix join format of parents keyword (issue5292)
Yuya Nishihara <yuya@tcha.org>
parents: 29623
diff changeset
166 if repo.ui.debugflag:
32678
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
167 hexfunc = hex
29624
1a129dd05b7d templatekw: fix join format of parents keyword (issue5292)
Yuya Nishihara <yuya@tcha.org>
parents: 29623
diff changeset
168 else:
32678
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
169 hexfunc = short
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
170 return '%d:%s' % (scmutil.intrev(ctx), hexfunc(scmutil.binnode(ctx)))
29624
1a129dd05b7d templatekw: fix join format of parents keyword (issue5292)
Yuya Nishihara <yuya@tcha.org>
parents: 29623
diff changeset
171
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
172 def getfiles(repo, ctx, revcache):
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
173 if 'files' not in revcache:
25392
ed18f4acf435 templatekw: compare target context and its parent exactly (issue4690)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24676
diff changeset
174 revcache['files'] = repo.status(ctx.p1(), ctx)[:3]
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
175 return revcache['files']
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
176
26482
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
177 def getlatesttags(repo, ctx, cache, pattern=None):
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
178 '''return date, distance and name for the latest tag of rev'''
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
179
26482
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
180 cachename = 'latesttags'
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
181 if pattern is not None:
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
182 cachename += '-' + pattern
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
183 match = util.stringmatcher(pattern)[2]
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
184 else:
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
185 match = util.always
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
186
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
187 if cachename not in cache:
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
188 # Cache mapping from rev to a tuple with tag date, tag
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
189 # distance and tag name
26482
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
190 cache[cachename] = {-1: (0, 0, ['null'])}
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
191 latesttags = cache[cachename]
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
192
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
193 rev = ctx.rev()
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
194 todo = [rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
195 while todo:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
196 rev = todo.pop()
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
197 if rev in latesttags:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
198 continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
199 ctx = repo[rev]
20218
0c22257388d6 templatekw: allow tagtypes other than global in getlatesttags
Andrew Shadura <andrew@shadura.me>
parents: 20183
diff changeset
200 tags = [t for t in ctx.tags()
26482
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
201 if (repo.tagtype(t) and repo.tagtype(t) != 'local'
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
202 and match(t))]
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
203 if tags:
25700
0fca47b206f6 templatekw: use a list of tags in getlatesttags() instead of joining them
Matt Harbison <matt_harbison@yahoo.com>
parents: 25663
diff changeset
204 latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
205 continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
206 try:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
207 # The tuples are laid out so the right one can be found by
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
208 # comparison.
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
209 pdate, pdist, ptag = max(
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
210 latesttags[p.rev()] for p in ctx.parents())
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
211 except KeyError:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
212 # Cache miss - recurse
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
213 todo.append(rev)
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
214 todo.extend(p.rev() for p in ctx.parents())
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
215 continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
216 latesttags[rev] = pdate, pdist + 1, ptag
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
217 return latesttags[rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
218
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
219 def getrenamedfn(repo, endrev=None):
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
220 rcache = {}
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
221 if endrev is None:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
222 endrev = len(repo)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
223
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
224 def getrenamed(fn, rev):
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
225 '''looks up all renames for a file (up to endrev) the first
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
226 time the file is given. It indexes on the changerev and only
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
227 parses the manifest if linkrev != changerev.
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
228 Returns rename info for fn at changerev rev.'''
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
229 if fn not in rcache:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
230 rcache[fn] = {}
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
231 fl = repo.file(fn)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
232 for i in fl:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
233 lr = fl.linkrev(i)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
234 renamed = fl.renamed(fl.node(i))
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
235 rcache[fn][lr] = renamed
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
236 if lr >= endrev:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
237 break
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
238 if rev in rcache[fn]:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
239 return rcache[fn][rev]
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
240
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
241 # If linkrev != rev (i.e. rev not found in rcache) fallback to
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
242 # filectx logic.
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
243 try:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
244 return repo[rev][fn].renamed()
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
245 except error.LookupError:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
246 return None
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
247
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
248 return getrenamed
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
249
31181
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
250 # default templates internally used for rendering of lists
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
251 defaulttempl = {
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
252 'parent': '{rev}:{node|formatnode} ',
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
253 'manifest': '{rev}:{node|formatnode}',
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
254 'file_copy': '{name} ({source})',
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
255 'envvar': '{key}={value}',
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
256 'extra': '{key}={value|stringescape}'
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
257 }
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
258 # filecopy is preserved for compatibility reasons
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
259 defaulttempl['filecopy'] = defaulttempl['file_copy']
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
260
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
261 # keywords are callables like:
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
262 # fn(repo, ctx, templ, cache, revcache, **args)
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
263 # with:
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
264 # repo - current repository instance
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
265 # ctx - the changectx being displayed
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
266 # templ - the templater instance
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
267 # cache - a cache dictionary for the whole templater run
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
268 # revcache - a cache dictionary for the current revision
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
269 keywords = {}
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
270
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
271 templatekeyword = registrar.templatekeyword(keywords)
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
272
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
273 @templatekeyword('author')
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
274 def showauthor(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
275 """String. The unmodified author of the changeset."""
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
276 return ctx.user()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
277
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
278 @templatekeyword('bisect')
15155
f4a8d754cd0a templates: add 'bisect' keyword to return a cset's bisect status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 14437
diff changeset
279 def showbisect(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
280 """String. The changeset bisection status."""
15155
f4a8d754cd0a templates: add 'bisect' keyword to return a cset's bisect status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 14437
diff changeset
281 return hbisect.label(repo, ctx.node())
f4a8d754cd0a templates: add 'bisect' keyword to return a cset's bisect status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 14437
diff changeset
282
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
283 @templatekeyword('branch')
13156
d79fdff55627 template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents: 13114
diff changeset
284 def showbranch(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
285 """String. The name of the branch on which the changeset was
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
286 committed.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
287 """
13156
d79fdff55627 template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents: 13114
diff changeset
288 return args['ctx'].branch()
d79fdff55627 template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents: 13114
diff changeset
289
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
290 @templatekeyword('branches')
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
291 def showbranches(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
292 """List of strings. The name of the branch on which the
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
293 changeset was committed. Will be empty if the branch name was
26437
4628b26f040e templatekw: hide help of "branches" by DEPRECATED marker
Yuya Nishihara <yuya@tcha.org>
parents: 26436
diff changeset
294 default. (DEPRECATED)
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
295 """
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
296 branch = args['ctx'].branch()
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
297 if branch != 'default':
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
298 return showlist('branch', [branch], args, plural='branches')
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
299 return showlist('branch', [], args, plural='branches')
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
300
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
301 @templatekeyword('bookmarks')
13386
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13156
diff changeset
302 def showbookmarks(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
303 """List of strings. Any bookmarks associated with the
25348
f26efa4f0eff templatekw: introduce active subkeyword from bookmarks keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25013
diff changeset
304 changeset. Also sets 'active', the name of the active bookmark.
13592
ad2ee188f4a5 templates: document missing keywords or filters
Patrick Mezard <pmezard@gmail.com>
parents: 13585
diff changeset
305 """
20520
5c65ee4193e1 template: add 'current' to scope during {bookmarks % ...}
Durham Goode <durham@fb.com>
parents: 20218
diff changeset
306 repo = args['ctx']._repo
13386
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13156
diff changeset
307 bookmarks = args['ctx'].bookmarks()
25348
f26efa4f0eff templatekw: introduce active subkeyword from bookmarks keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25013
diff changeset
308 active = repo._activebookmark
f26efa4f0eff templatekw: introduce active subkeyword from bookmarks keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25013
diff changeset
309 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
32036
8bcc8c9b4e9f templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents: 32035
diff changeset
310 f = _showlist('bookmark', bookmarks, args)
24239
31f9b1b16d1e templatekw: keep raw list or dict in _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 24238
diff changeset
311 return _hybrid(f, bookmarks, makemap, lambda x: x['bookmark'])
13386
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13156
diff changeset
312
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
313 @templatekeyword('children')
11655
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
314 def showchildren(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
315 """List of strings. The children of the changeset."""
11655
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
316 ctx = args['ctx']
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
317 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
318 return showlist('children', childrevs, args, element='child')
11655
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
319
25013
277aba2c151a templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25012
diff changeset
320 # Deprecated, but kept alive for help generation a purpose.
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
321 @templatekeyword('currentbookmark')
21896
2b41ee1b5ea1 templatekw: add 'currentbookmark' keyword to show current bookmark easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20683
diff changeset
322 def showcurrentbookmark(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
323 """String. The active bookmark, if it is
25013
277aba2c151a templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25012
diff changeset
324 associated with the changeset (DEPRECATED)"""
277aba2c151a templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25012
diff changeset
325 return showactivebookmark(**args)
277aba2c151a templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25012
diff changeset
326
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
327 @templatekeyword('activebookmark')
25013
277aba2c151a templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25012
diff changeset
328 def showactivebookmark(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
329 """String. The active bookmark, if it is
21896
2b41ee1b5ea1 templatekw: add 'currentbookmark' keyword to show current bookmark easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20683
diff changeset
330 associated with the changeset"""
25387
390a10b7843b templatekw: display active bookmark more consistently (issue4552) (BC)
Ryan McElroy <rmcelroy@fb.com>
parents: 25348
diff changeset
331 active = args['repo']._activebookmark
390a10b7843b templatekw: display active bookmark more consistently (issue4552) (BC)
Ryan McElroy <rmcelroy@fb.com>
parents: 25348
diff changeset
332 if active and active in args['ctx'].bookmarks():
390a10b7843b templatekw: display active bookmark more consistently (issue4552) (BC)
Ryan McElroy <rmcelroy@fb.com>
parents: 25348
diff changeset
333 return active
21896
2b41ee1b5ea1 templatekw: add 'currentbookmark' keyword to show current bookmark easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20683
diff changeset
334 return ''
2b41ee1b5ea1 templatekw: add 'currentbookmark' keyword to show current bookmark easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20683
diff changeset
335
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
336 @templatekeyword('date')
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
337 def showdate(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
338 """Date information. The date when the changeset was committed."""
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
339 return ctx.date()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
340
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
341 @templatekeyword('desc')
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
342 def showdescription(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
343 """String. The text of the changeset description."""
28239
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
344 s = ctx.description()
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
345 if isinstance(s, encoding.localstr):
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
346 # try hard to preserve utf-8 bytes
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
347 return encoding.tolocal(encoding.fromlocal(s).strip())
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
348 else:
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
349 return s.strip()
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
350
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
351 @templatekeyword('diffstat')
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
352 def showdiffstat(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
353 """String. Statistics of changes with the following format:
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
354 "modified files: +added/-removed lines"
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
355 """
30811
cf1e15f91c90 templatekw: force noprefix=False to insure diffstat consistency (issue4755)
Matthieu Laneuville <mlaneuville@protonmail.com>
parents: 30712
diff changeset
356 stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False)))
14437
cbe13e6bdc34 patch: restore the previous output of 'diff --stat'
Steven Brown <StevenGBrown@gmail.com>
parents: 14403
diff changeset
357 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
14403
2c9f5897d4b7 templatekw: use diffstatsum in diffstat keyword
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
358 return '%s: +%s/-%s' % (len(stats), adds, removes)
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
359
30833
bd5e9647f646 templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents: 30811
diff changeset
360 @templatekeyword('envvars')
bd5e9647f646 templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents: 30811
diff changeset
361 def showenvvars(repo, **args):
bd5e9647f646 templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents: 30811
diff changeset
362 """A dictionary of environment variables. (EXPERIMENTAL)"""
bd5e9647f646 templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents: 30811
diff changeset
363 env = repo.ui.exportableenviron()
bd5e9647f646 templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents: 30811
diff changeset
364 env = util.sortdict((k, env[k]) for k in sorted(env))
32038
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
365 return showdict('envvar', env, args, plural='envvars')
30833
bd5e9647f646 templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents: 30811
diff changeset
366
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
367 @templatekeyword('extras')
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
368 def showextras(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
369 """List of dicts with key, value entries of the 'extras'
20015
ad27cdacc743 help: document about {extras} template keyword
Matthew Turk <matthewturk@gmail.com>
parents: 18970
diff changeset
370 field of this changeset."""
20183
de7e6c489412 template: modify showextras to return a hybrid
Matthew Turk <matthewturk@gmail.com>
parents: 20079
diff changeset
371 extras = args['ctx'].extra()
24237
9ad02823dc5b templatekw: convert list of key/value pairs to sortdict
Yuya Nishihara <yuya@tcha.org>
parents: 24157
diff changeset
372 extras = util.sortdict((k, extras[k]) for k in sorted(extras))
24238
49cee6d8573d templatekw: give name to lambda that constructs variables map of templater
Yuya Nishihara <yuya@tcha.org>
parents: 24237
diff changeset
373 makemap = lambda k: {'key': k, 'value': extras[k]}
49cee6d8573d templatekw: give name to lambda that constructs variables map of templater
Yuya Nishihara <yuya@tcha.org>
parents: 24237
diff changeset
374 c = [makemap(k) for k in extras]
32036
8bcc8c9b4e9f templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents: 32035
diff changeset
375 f = _showlist('extra', c, args, plural='extras')
24239
31f9b1b16d1e templatekw: keep raw list or dict in _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents: 24238
diff changeset
376 return _hybrid(f, extras, makemap,
31461
52dabcc49968 templatekw: make join() escape values of extras (BC) (issue5504)
Yuya Nishihara <yuya@tcha.org>
parents: 31181
diff changeset
377 lambda x: '%s=%s' % (x['key'], util.escapestr(x['value'])))
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
378
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
379 @templatekeyword('file_adds')
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
380 def showfileadds(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
381 """List of strings. Files added by this changeset."""
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
382 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
383 return showlist('file_add', getfiles(repo, ctx, revcache)[1], args,
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
384 element='file')
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
385
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
386 @templatekeyword('file_copies')
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
387 def showfilecopies(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
388 """List of strings. Files copied in this changeset with
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
389 their sources.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
390 """
10394
4612cded5176 fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
391 cache, ctx = args['cache'], args['ctx']
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
392 copies = args['revcache'].get('copies')
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
393 if copies is None:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
394 if 'getrenamed' not in cache:
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
395 cache['getrenamed'] = getrenamedfn(args['repo'])
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
396 copies = []
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
397 getrenamed = cache['getrenamed']
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
398 for fn in ctx.files():
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
399 rename = getrenamed(fn, ctx.rev())
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
400 if rename:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
401 copies.append((fn, rename[0]))
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
402
24237
9ad02823dc5b templatekw: convert list of key/value pairs to sortdict
Yuya Nishihara <yuya@tcha.org>
parents: 24157
diff changeset
403 copies = util.sortdict(copies)
32038
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
404 return showdict('file_copy', copies, args, plural='file_copies',
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
405 key='name', value='source', fmt='%s (%s)')
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
406
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
407 # showfilecopiesswitch() displays file copies only if copy records are
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
408 # provided before calling the templater, usually with a --copies
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
409 # command line switch.
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
410 @templatekeyword('file_copies_switch')
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
411 def showfilecopiesswitch(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
412 """List of strings. Like "file_copies" but displayed
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
413 only if the --copied switch is set.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
414 """
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
415 copies = args['revcache'].get('copies') or []
24237
9ad02823dc5b templatekw: convert list of key/value pairs to sortdict
Yuya Nishihara <yuya@tcha.org>
parents: 24157
diff changeset
416 copies = util.sortdict(copies)
32038
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
417 return showdict('file_copy', copies, args, plural='file_copies',
3920b5970f95 templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents: 32037
diff changeset
418 key='name', value='source', fmt='%s (%s)')
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
419
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
420 @templatekeyword('file_dels')
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
421 def showfiledels(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
422 """List of strings. Files removed by this changeset."""
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
423 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
424 return showlist('file_del', getfiles(repo, ctx, revcache)[2], args,
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
425 element='file')
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
426
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
427 @templatekeyword('file_mods')
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
428 def showfilemods(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
429 """List of strings. Files modified by this changeset."""
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
430 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
431 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], args,
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
432 element='file')
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
433
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
434 @templatekeyword('files')
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
435 def showfiles(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
436 """List of strings. All files modified, added, or removed by this
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
437 changeset.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
438 """
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
439 return showlist('file', args['ctx'].files(), args)
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
440
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
441 @templatekeyword('graphnode')
27214
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
442 def showgraphnode(repo, ctx, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
443 """String. The character representing the changeset node in
27214
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
444 an ASCII revision graph"""
27215
5b8da5643a8a templatekw: avoid slow creation of changectx objects in showgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
445 wpnodes = repo.dirstate.parents()
5b8da5643a8a templatekw: avoid slow creation of changectx objects in showgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
446 if wpnodes[1] == nullid:
5b8da5643a8a templatekw: avoid slow creation of changectx objects in showgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
447 wpnodes = wpnodes[:1]
27214
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
448 if ctx.node() in wpnodes:
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
449 return '@'
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
450 elif ctx.obsolete():
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
451 return 'x'
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
452 elif ctx.closesbranch():
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
453 return '_'
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
454 else:
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
455 return 'o'
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
456
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
457 @templatekeyword('index')
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
458 def showindex(**args):
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
459 """Integer. The current iteration of the loop. (0 indexed)"""
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
460 # just hosts documentation; should be overridden by template mapping
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
461 raise error.Abort(_("can't use index in this context"))
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
462
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
463 @templatekeyword('latesttag')
25727
b8245386ab40 templatekw: make {latesttag} a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 25726
diff changeset
464 def showlatesttag(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
465 """List of strings. The global tags on the most recent globally
31850
f0d719e513fc templatekw: clarify the result of {latesttag} when no tag exists
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
466 tagged ancestor of this changeset. If no such tags exist, the list
f0d719e513fc templatekw: clarify the result of {latesttag} when no tag exists
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
467 consists of the single string "null".
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
468 """
26486
8a732c322ca7 templatekw: add {changes}, {distance} and {tag} to the {latesttag} keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 26484
diff changeset
469 return showlatesttags(None, **args)
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
470
26484
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
471 def showlatesttags(pattern, **args):
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
472 """helper method for the latesttag keyword and function"""
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
473 repo, ctx = args['repo'], args['ctx']
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
474 cache = args['cache']
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
475 latesttags = getlatesttags(repo, ctx, cache, pattern)
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
476
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
477 # latesttag[0] is an implementation detail for sorting csets on different
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
478 # branches in a stable manner- it is the date the tagged cset was created,
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
479 # not the date the tag was created. Therefore it isn't made visible here.
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
480 makemap = lambda v: {
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
481 'changes': _showchangessincetag,
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
482 'distance': latesttags[1],
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
483 'latesttag': v, # BC with {latesttag % '{latesttag}'}
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
484 'tag': v
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
485 }
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
486
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
487 tags = latesttags[2]
32036
8bcc8c9b4e9f templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents: 32035
diff changeset
488 f = _showlist('latesttag', tags, args, separator=':')
26484
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
489 return _hybrid(f, tags, makemap, lambda x: x['latesttag'])
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
490
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
491 @templatekeyword('latesttagdistance')
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
492 def showlatesttagdistance(repo, ctx, templ, cache, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
493 """Integer. Longest path to the latest tag."""
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
494 return getlatesttags(repo, ctx, cache)[1]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
495
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
496 @templatekeyword('changessincelatesttag')
25724
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
497 def showchangessincelatesttag(repo, ctx, templ, cache, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
498 """Integer. All ancestors not in the latest tag."""
25724
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
499 latesttag = getlatesttags(repo, ctx, cache)[2][0]
26483
e94f93043a4e templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents: 26482
diff changeset
500
e94f93043a4e templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents: 26482
diff changeset
501 return _showchangessincetag(repo, ctx, tag=latesttag, **args)
e94f93043a4e templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents: 26482
diff changeset
502
e94f93043a4e templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents: 26482
diff changeset
503 def _showchangessincetag(repo, ctx, **args):
25724
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
504 offset = 0
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
505 revs = [ctx.rev()]
26483
e94f93043a4e templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents: 26482
diff changeset
506 tag = args['tag']
25724
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
507
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
508 # The only() revset doesn't currently support wdir()
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
509 if ctx.rev() is None:
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
510 offset = 1
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
511 revs = [p.rev() for p in ctx.parents()]
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
512
26483
e94f93043a4e templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents: 26482
diff changeset
513 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset
25724
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
514
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
515 @templatekeyword('manifest')
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
516 def showmanifest(**args):
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
517 repo, ctx, templ = args['repo'], args['ctx'], args['templ']
24676
13c42a883e8b templatekw: have {manifest} use ctx.manifestnode() for consistency
Yuya Nishihara <yuya@tcha.org>
parents: 24337
diff changeset
518 mnode = ctx.manifestnode()
25736
8854ca3fa675 templatekw: apply manifest template only if ctx.manifestnode() exists
Yuya Nishihara <yuya@tcha.org>
parents: 25727
diff changeset
519 if mnode is None:
8854ca3fa675 templatekw: apply manifest template only if ctx.manifestnode() exists
Yuya Nishihara <yuya@tcha.org>
parents: 25727
diff changeset
520 # just avoid crash, we might want to use the 'ff...' hash in future
8854ca3fa675 templatekw: apply manifest template only if ctx.manifestnode() exists
Yuya Nishihara <yuya@tcha.org>
parents: 25727
diff changeset
521 return
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
522 args = args.copy()
30385
11b8b740d54a manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents: 30088
diff changeset
523 args.update({'rev': repo.manifestlog._revlog.rev(mnode),
11b8b740d54a manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents: 30088
diff changeset
524 'node': hex(mnode)})
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
525 return templ('manifest', **args)
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
526
27893
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
527 def shownames(namespace, **args):
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
528 """helper method to generate a template keyword for a namespace"""
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
529 ctx = args['ctx']
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
530 repo = ctx.repo()
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
531 ns = repo.names[namespace]
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
532 names = ns.names(repo, ctx.node())
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
533 return showlist(ns.templatename, names, args, plural=namespace)
27893
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
534
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
535 @templatekeyword('namespaces')
27894
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
536 def shownamespaces(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
537 """Dict of lists. Names attached to this changeset per
27894
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
538 namespace."""
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
539 ctx = args['ctx']
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
540 repo = ctx.repo()
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
541 namespaces = util.sortdict((k, showlist('name', ns.names(repo, ctx.node()),
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
542 args))
27894
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
543 for k, ns in repo.names.iteritems())
32036
8bcc8c9b4e9f templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents: 32035
diff changeset
544 f = _showlist('namespace', list(namespaces), args)
27894
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
545 return _hybrid(f, namespaces,
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
546 lambda k: {'namespace': k, 'names': namespaces[k]},
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
547 lambda x: x['namespace'])
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
548
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
549 @templatekeyword('node')
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
550 def shownode(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
551 """String. The changeset identification hash, as a 40 hexadecimal
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
552 digit string.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
553 """
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
554 return ctx.hex()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
555
31704
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
556 @templatekeyword('obsolete')
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
557 def showobsolete(repo, ctx, templ, **args):
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
558 """String. Whether the changeset is obsolete.
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
559 """
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
560 if ctx.obsolete():
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
561 return 'obsolete'
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
562 return ''
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
563
32897
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
564 @templatekeyword("predecessors")
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
565 def showpredecessors(repo, ctx, **args):
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
566 """Returns the list if the closest visible successors
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
567 """
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
568 predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node()))
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
569 predecessors = map(hex, predecessors)
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
570
32928
498e9dcc5fa9 templatekw: populate all keywords depending on predecessor in map operation
Yuya Nishihara <yuya@tcha.org>
parents: 32927
diff changeset
571 return _hybrid(None, predecessors,
498e9dcc5fa9 templatekw: populate all keywords depending on predecessor in map operation
Yuya Nishihara <yuya@tcha.org>
parents: 32927
diff changeset
572 lambda x: {'ctx': repo[x], 'revcache': {}},
498e9dcc5fa9 templatekw: populate all keywords depending on predecessor in map operation
Yuya Nishihara <yuya@tcha.org>
parents: 32927
diff changeset
573 lambda d: short(scmutil.binnode(d['ctx'])))
32897
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
574
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
575 @templatekeyword('p1rev')
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
576 def showp1rev(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
577 """Integer. The repository-local revision number of the changeset's
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
578 first parent, or -1 if the changeset has no parents."""
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
579 return ctx.p1().rev()
17355
c25531ed58b0 templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
580
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
581 @templatekeyword('p2rev')
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
582 def showp2rev(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
583 """Integer. The repository-local revision number of the changeset's
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
584 second parent, or -1 if the changeset has no second parent."""
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
585 return ctx.p2().rev()
17355
c25531ed58b0 templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
586
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
587 @templatekeyword('p1node')
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
588 def showp1node(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
589 """String. The identification hash of the changeset's first parent,
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
590 as a 40 digit hexadecimal string. If the changeset has no parents, all
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
591 digits are 0."""
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
592 return ctx.p1().hex()
17355
c25531ed58b0 templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
593
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
594 @templatekeyword('p2node')
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
595 def showp2node(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
596 """String. The identification hash of the changeset's second
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
597 parent, as a 40 digit hexadecimal string. If the changeset has no second
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
598 parent, all digits are 0."""
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
599 return ctx.p2().hex()
17355
c25531ed58b0 templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
600
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
601 @templatekeyword('parents')
26435
882b170ae616 templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 26434
diff changeset
602 def showparents(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
603 """List of strings. The parents of the changeset in "rev:node"
26434
0a823de8d7b7 templatekw: reorder stub of showparents() function
Yuya Nishihara <yuya@tcha.org>
parents: 26234
diff changeset
604 format. If the changeset has only one "natural" parent (the predecessor
0a823de8d7b7 templatekw: reorder stub of showparents() function
Yuya Nishihara <yuya@tcha.org>
parents: 26234
diff changeset
605 revision) nothing is shown."""
26435
882b170ae616 templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 26434
diff changeset
606 repo = args['repo']
882b170ae616 templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 26434
diff changeset
607 ctx = args['ctx']
28270
650c9f69a744 templatekw: switch ctx of list expression to rev of {parents} (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 28239
diff changeset
608 pctxs = scmutil.meaningfulparents(repo, ctx)
650c9f69a744 templatekw: switch ctx of list expression to rev of {parents} (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 28239
diff changeset
609 prevs = [str(p.rev()) for p in pctxs] # ifcontains() needs a list of str
26435
882b170ae616 templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 26434
diff changeset
610 parents = [[('rev', p.rev()),
882b170ae616 templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 26434
diff changeset
611 ('node', p.hex()),
882b170ae616 templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 26434
diff changeset
612 ('phase', p.phasestr())]
28270
650c9f69a744 templatekw: switch ctx of list expression to rev of {parents} (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 28239
diff changeset
613 for p in pctxs]
32036
8bcc8c9b4e9f templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents: 32035
diff changeset
614 f = _showlist('parent', parents, args)
29624
1a129dd05b7d templatekw: fix join format of parents keyword (issue5292)
Yuya Nishihara <yuya@tcha.org>
parents: 29623
diff changeset
615 return _hybrid(f, prevs, lambda x: {'ctx': repo[int(x)], 'revcache': {}},
1a129dd05b7d templatekw: fix join format of parents keyword (issue5292)
Yuya Nishihara <yuya@tcha.org>
parents: 29623
diff changeset
616 lambda d: _formatrevnode(d['ctx']))
26434
0a823de8d7b7 templatekw: reorder stub of showparents() function
Yuya Nishihara <yuya@tcha.org>
parents: 26234
diff changeset
617
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
618 @templatekeyword('phase')
15422
042e11c4e416 phases: add a phase template keyword
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15155
diff changeset
619 def showphase(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
620 """String. The changeset phase name."""
15823
a1f818a2b50d phases: ``{phase}`` template keyword display the phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15422
diff changeset
621 return ctx.phasestr()
a1f818a2b50d phases: ``{phase}`` template keyword display the phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15422
diff changeset
622
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
623 @templatekeyword('phaseidx')
15823
a1f818a2b50d phases: ``{phase}`` template keyword display the phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15422
diff changeset
624 def showphaseidx(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
625 """Integer. The changeset phase index."""
15422
042e11c4e416 phases: add a phase template keyword
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15155
diff changeset
626 return ctx.phase()
042e11c4e416 phases: add a phase template keyword
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15155
diff changeset
627
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
628 @templatekeyword('rev')
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
629 def showrev(repo, ctx, templ, **args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
630 """Integer. The repository-local changeset revision number."""
32676
4bec8cce6a09 scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents: 32038
diff changeset
631 return scmutil.intrev(ctx)
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
632
26234
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 25984
diff changeset
633 def showrevslist(name, revs, **args):
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 25984
diff changeset
634 """helper to generate a list of revisions in which a mapped template will
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 25984
diff changeset
635 be evaluated"""
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 25984
diff changeset
636 repo = args['ctx'].repo()
28178
96f2d50fb9f6 templater: factor out type conversion of revset() result
Yuya Nishihara <yuya@tcha.org>
parents: 28177
diff changeset
637 revs = [str(r) for r in revs] # ifcontains() needs a list of str
32036
8bcc8c9b4e9f templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents: 32035
diff changeset
638 f = _showlist(name, revs, args)
26234
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 25984
diff changeset
639 return _hybrid(f, revs,
29623
33bf8bd8c5b9 templatekw: fix join format of revset() function
Yuya Nishihara <yuya@tcha.org>
parents: 28539
diff changeset
640 lambda x: {name: x, 'ctx': repo[int(x)], 'revcache': {}},
33bf8bd8c5b9 templatekw: fix join format of revset() function
Yuya Nishihara <yuya@tcha.org>
parents: 28539
diff changeset
641 lambda d: d[name])
26234
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 25984
diff changeset
642
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
643 @templatekeyword('subrepos')
21897
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
644 def showsubrepos(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
645 """List of strings. Updated subrepositories in the changeset."""
21897
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
646 ctx = args['ctx']
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
647 substate = ctx.substate
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
648 if not substate:
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
649 return showlist('subrepo', [], args)
21897
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
650 psubstate = ctx.parents()[0].substate or {}
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
651 subrepos = []
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
652 for sub in substate:
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
653 if sub not in psubstate or substate[sub] != psubstate[sub]:
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
654 subrepos.append(sub) # modified or newly added in ctx
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
655 for sub in psubstate:
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
656 if sub not in substate:
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
657 subrepos.append(sub) # removed in ctx
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
658 return showlist('subrepo', sorted(subrepos), args)
21897
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
659
23977
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
660 # don't remove "showtags" definition, even though namespaces will put
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
661 # a helper function for "tags" keyword into "keywords" map automatically,
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
662 # because online help text is built without namespaces initialization
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
663 @templatekeyword('tags')
23977
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
664 def showtags(**args):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
665 """List of strings. Any tags associated with the changeset."""
23977
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
666 return shownames('tags', **args)
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
667
28538
009f58f1ea75 registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28270
diff changeset
668 def loadkeyword(ui, extname, registrarobj):
009f58f1ea75 registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28270
diff changeset
669 """Load template keyword from specified registrarobj
009f58f1ea75 registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28270
diff changeset
670 """
009f58f1ea75 registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28270
diff changeset
671 for name, func in registrarobj._table.iteritems():
009f58f1ea75 registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28270
diff changeset
672 keywords[name] = func
009f58f1ea75 registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28270
diff changeset
673
30088
d1f5f158768e template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents: 29683
diff changeset
674 @templatekeyword('termwidth')
d1f5f158768e template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents: 29683
diff changeset
675 def termwidth(repo, ctx, templ, **args):
d1f5f158768e template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents: 29683
diff changeset
676 """Integer. The width of the current terminal."""
d1f5f158768e template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents: 29683
diff changeset
677 return repo.ui.termwidth()
d1f5f158768e template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents: 29683
diff changeset
678
30712
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
679 @templatekeyword('troubles')
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
680 def showtroubles(**args):
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
681 """List of strings. Evolution troubles affecting the changeset.
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
682
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
683 (EXPERIMENTAL)
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
684 """
32037
e5eab0fe69ee templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32036
diff changeset
685 return showlist('trouble', args['ctx'].troubles(), args)
30712
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
686
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
687 # tell hggettext to extract docstrings from these functions:
26436
a2291c9c85a1 templatekw: remove dockeywords hack
Yuya Nishihara <yuya@tcha.org>
parents: 26435
diff changeset
688 i18nfunctions = keywords.values()