##// END OF EJS Templates
help: hide template keywords of obsolescence as they are still experimental
Yuya Nishihara -
r34658:bfb6fd93 default
parent child Browse files
Show More
@@ -1,879 +1,878 b''
1 # templatekw.py - common changeset template keywords
1 # templatekw.py - common changeset template keywords
2 #
2 #
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from .i18n import _
10 from .i18n import _
11 from .node import (
11 from .node import (
12 hex,
12 hex,
13 nullid,
13 nullid,
14 )
14 )
15
15
16 from . import (
16 from . import (
17 encoding,
17 encoding,
18 error,
18 error,
19 hbisect,
19 hbisect,
20 obsutil,
20 obsutil,
21 patch,
21 patch,
22 pycompat,
22 pycompat,
23 registrar,
23 registrar,
24 scmutil,
24 scmutil,
25 util,
25 util,
26 )
26 )
27
27
28 class _hybrid(object):
28 class _hybrid(object):
29 """Wrapper for list or dict to support legacy template
29 """Wrapper for list or dict to support legacy template
30
30
31 This class allows us to handle both:
31 This class allows us to handle both:
32 - "{files}" (legacy command-line-specific list hack) and
32 - "{files}" (legacy command-line-specific list hack) and
33 - "{files % '{file}\n'}" (hgweb-style with inlining and function support)
33 - "{files % '{file}\n'}" (hgweb-style with inlining and function support)
34 and to access raw values:
34 and to access raw values:
35 - "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}"
35 - "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}"
36 - "{get(extras, key)}"
36 - "{get(extras, key)}"
37 - "{files|json}"
37 - "{files|json}"
38 """
38 """
39
39
40 def __init__(self, gen, values, makemap, joinfmt, keytype=None):
40 def __init__(self, gen, values, makemap, joinfmt, keytype=None):
41 if gen is not None:
41 if gen is not None:
42 self.gen = gen # generator or function returning generator
42 self.gen = gen # generator or function returning generator
43 self._values = values
43 self._values = values
44 self._makemap = makemap
44 self._makemap = makemap
45 self.joinfmt = joinfmt
45 self.joinfmt = joinfmt
46 self.keytype = keytype # hint for 'x in y' where type(x) is unresolved
46 self.keytype = keytype # hint for 'x in y' where type(x) is unresolved
47 def gen(self):
47 def gen(self):
48 """Default generator to stringify this as {join(self, ' ')}"""
48 """Default generator to stringify this as {join(self, ' ')}"""
49 for i, x in enumerate(self._values):
49 for i, x in enumerate(self._values):
50 if i > 0:
50 if i > 0:
51 yield ' '
51 yield ' '
52 yield self.joinfmt(x)
52 yield self.joinfmt(x)
53 def itermaps(self):
53 def itermaps(self):
54 makemap = self._makemap
54 makemap = self._makemap
55 for x in self._values:
55 for x in self._values:
56 yield makemap(x)
56 yield makemap(x)
57 def __contains__(self, x):
57 def __contains__(self, x):
58 return x in self._values
58 return x in self._values
59 def __getitem__(self, key):
59 def __getitem__(self, key):
60 return self._values[key]
60 return self._values[key]
61 def __len__(self):
61 def __len__(self):
62 return len(self._values)
62 return len(self._values)
63 def __iter__(self):
63 def __iter__(self):
64 return iter(self._values)
64 return iter(self._values)
65 def __getattr__(self, name):
65 def __getattr__(self, name):
66 if name not in ('get', 'items', 'iteritems', 'iterkeys', 'itervalues',
66 if name not in ('get', 'items', 'iteritems', 'iterkeys', 'itervalues',
67 'keys', 'values'):
67 'keys', 'values'):
68 raise AttributeError(name)
68 raise AttributeError(name)
69 return getattr(self._values, name)
69 return getattr(self._values, name)
70
70
71 class _mappable(object):
71 class _mappable(object):
72 """Wrapper for non-list/dict object to support map operation
72 """Wrapper for non-list/dict object to support map operation
73
73
74 This class allows us to handle both:
74 This class allows us to handle both:
75 - "{manifest}"
75 - "{manifest}"
76 - "{manifest % '{rev}:{node}'}"
76 - "{manifest % '{rev}:{node}'}"
77 - "{manifest.rev}"
77 - "{manifest.rev}"
78
78
79 Unlike a _hybrid, this does not simulate the behavior of the underling
79 Unlike a _hybrid, this does not simulate the behavior of the underling
80 value. Use unwrapvalue() or unwraphybrid() to obtain the inner object.
80 value. Use unwrapvalue() or unwraphybrid() to obtain the inner object.
81 """
81 """
82
82
83 def __init__(self, gen, key, value, makemap):
83 def __init__(self, gen, key, value, makemap):
84 if gen is not None:
84 if gen is not None:
85 self.gen = gen # generator or function returning generator
85 self.gen = gen # generator or function returning generator
86 self._key = key
86 self._key = key
87 self._value = value # may be generator of strings
87 self._value = value # may be generator of strings
88 self._makemap = makemap
88 self._makemap = makemap
89
89
90 def gen(self):
90 def gen(self):
91 yield pycompat.bytestr(self._value)
91 yield pycompat.bytestr(self._value)
92
92
93 def tomap(self):
93 def tomap(self):
94 return self._makemap(self._key)
94 return self._makemap(self._key)
95
95
96 def itermaps(self):
96 def itermaps(self):
97 yield self.tomap()
97 yield self.tomap()
98
98
99 def hybriddict(data, key='key', value='value', fmt='%s=%s', gen=None):
99 def hybriddict(data, key='key', value='value', fmt='%s=%s', gen=None):
100 """Wrap data to support both dict-like and string-like operations"""
100 """Wrap data to support both dict-like and string-like operations"""
101 return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
101 return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
102 lambda k: fmt % (k, data[k]))
102 lambda k: fmt % (k, data[k]))
103
103
104 def hybridlist(data, name, fmt='%s', gen=None):
104 def hybridlist(data, name, fmt='%s', gen=None):
105 """Wrap data to support both list-like and string-like operations"""
105 """Wrap data to support both list-like and string-like operations"""
106 return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % x)
106 return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % x)
107
107
108 def unwraphybrid(thing):
108 def unwraphybrid(thing):
109 """Return an object which can be stringified possibly by using a legacy
109 """Return an object which can be stringified possibly by using a legacy
110 template"""
110 template"""
111 gen = getattr(thing, 'gen', None)
111 gen = getattr(thing, 'gen', None)
112 if gen is None:
112 if gen is None:
113 return thing
113 return thing
114 if callable(gen):
114 if callable(gen):
115 return gen()
115 return gen()
116 return gen
116 return gen
117
117
118 def unwrapvalue(thing):
118 def unwrapvalue(thing):
119 """Move the inner value object out of the wrapper"""
119 """Move the inner value object out of the wrapper"""
120 if not util.safehasattr(thing, '_value'):
120 if not util.safehasattr(thing, '_value'):
121 return thing
121 return thing
122 return thing._value
122 return thing._value
123
123
124 def wraphybridvalue(container, key, value):
124 def wraphybridvalue(container, key, value):
125 """Wrap an element of hybrid container to be mappable
125 """Wrap an element of hybrid container to be mappable
126
126
127 The key is passed to the makemap function of the given container, which
127 The key is passed to the makemap function of the given container, which
128 should be an item generated by iter(container).
128 should be an item generated by iter(container).
129 """
129 """
130 makemap = getattr(container, '_makemap', None)
130 makemap = getattr(container, '_makemap', None)
131 if makemap is None:
131 if makemap is None:
132 return value
132 return value
133 if util.safehasattr(value, '_makemap'):
133 if util.safehasattr(value, '_makemap'):
134 # a nested hybrid list/dict, which has its own way of map operation
134 # a nested hybrid list/dict, which has its own way of map operation
135 return value
135 return value
136 return _mappable(None, key, value, makemap)
136 return _mappable(None, key, value, makemap)
137
137
138 def showdict(name, data, mapping, plural=None, key='key', value='value',
138 def showdict(name, data, mapping, plural=None, key='key', value='value',
139 fmt='%s=%s', separator=' '):
139 fmt='%s=%s', separator=' '):
140 c = [{key: k, value: v} for k, v in data.iteritems()]
140 c = [{key: k, value: v} for k, v in data.iteritems()]
141 f = _showlist(name, c, mapping, plural, separator)
141 f = _showlist(name, c, mapping, plural, separator)
142 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
142 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
143
143
144 def showlist(name, values, mapping, plural=None, element=None, separator=' '):
144 def showlist(name, values, mapping, plural=None, element=None, separator=' '):
145 if not element:
145 if not element:
146 element = name
146 element = name
147 f = _showlist(name, values, mapping, plural, separator)
147 f = _showlist(name, values, mapping, plural, separator)
148 return hybridlist(values, name=element, gen=f)
148 return hybridlist(values, name=element, gen=f)
149
149
150 def _showlist(name, values, mapping, plural=None, separator=' '):
150 def _showlist(name, values, mapping, plural=None, separator=' '):
151 '''expand set of values.
151 '''expand set of values.
152 name is name of key in template map.
152 name is name of key in template map.
153 values is list of strings or dicts.
153 values is list of strings or dicts.
154 plural is plural of name, if not simply name + 's'.
154 plural is plural of name, if not simply name + 's'.
155 separator is used to join values as a string
155 separator is used to join values as a string
156
156
157 expansion works like this, given name 'foo'.
157 expansion works like this, given name 'foo'.
158
158
159 if values is empty, expand 'no_foos'.
159 if values is empty, expand 'no_foos'.
160
160
161 if 'foo' not in template map, return values as a string,
161 if 'foo' not in template map, return values as a string,
162 joined by 'separator'.
162 joined by 'separator'.
163
163
164 expand 'start_foos'.
164 expand 'start_foos'.
165
165
166 for each value, expand 'foo'. if 'last_foo' in template
166 for each value, expand 'foo'. if 'last_foo' in template
167 map, expand it instead of 'foo' for last key.
167 map, expand it instead of 'foo' for last key.
168
168
169 expand 'end_foos'.
169 expand 'end_foos'.
170 '''
170 '''
171 templ = mapping['templ']
171 templ = mapping['templ']
172 strmapping = pycompat.strkwargs(mapping)
172 strmapping = pycompat.strkwargs(mapping)
173 if not plural:
173 if not plural:
174 plural = name + 's'
174 plural = name + 's'
175 if not values:
175 if not values:
176 noname = 'no_' + plural
176 noname = 'no_' + plural
177 if noname in templ:
177 if noname in templ:
178 yield templ(noname, **strmapping)
178 yield templ(noname, **strmapping)
179 return
179 return
180 if name not in templ:
180 if name not in templ:
181 if isinstance(values[0], bytes):
181 if isinstance(values[0], bytes):
182 yield separator.join(values)
182 yield separator.join(values)
183 else:
183 else:
184 for v in values:
184 for v in values:
185 yield dict(v, **strmapping)
185 yield dict(v, **strmapping)
186 return
186 return
187 startname = 'start_' + plural
187 startname = 'start_' + plural
188 if startname in templ:
188 if startname in templ:
189 yield templ(startname, **strmapping)
189 yield templ(startname, **strmapping)
190 vmapping = mapping.copy()
190 vmapping = mapping.copy()
191 def one(v, tag=name):
191 def one(v, tag=name):
192 try:
192 try:
193 vmapping.update(v)
193 vmapping.update(v)
194 except (AttributeError, ValueError):
194 except (AttributeError, ValueError):
195 try:
195 try:
196 for a, b in v:
196 for a, b in v:
197 vmapping[a] = b
197 vmapping[a] = b
198 except ValueError:
198 except ValueError:
199 vmapping[name] = v
199 vmapping[name] = v
200 return templ(tag, **pycompat.strkwargs(vmapping))
200 return templ(tag, **pycompat.strkwargs(vmapping))
201 lastname = 'last_' + name
201 lastname = 'last_' + name
202 if lastname in templ:
202 if lastname in templ:
203 last = values.pop()
203 last = values.pop()
204 else:
204 else:
205 last = None
205 last = None
206 for v in values:
206 for v in values:
207 yield one(v)
207 yield one(v)
208 if last is not None:
208 if last is not None:
209 yield one(last, tag=lastname)
209 yield one(last, tag=lastname)
210 endname = 'end_' + plural
210 endname = 'end_' + plural
211 if endname in templ:
211 if endname in templ:
212 yield templ(endname, **strmapping)
212 yield templ(endname, **strmapping)
213
213
214 def getfiles(repo, ctx, revcache):
214 def getfiles(repo, ctx, revcache):
215 if 'files' not in revcache:
215 if 'files' not in revcache:
216 revcache['files'] = repo.status(ctx.p1(), ctx)[:3]
216 revcache['files'] = repo.status(ctx.p1(), ctx)[:3]
217 return revcache['files']
217 return revcache['files']
218
218
219 def getlatesttags(repo, ctx, cache, pattern=None):
219 def getlatesttags(repo, ctx, cache, pattern=None):
220 '''return date, distance and name for the latest tag of rev'''
220 '''return date, distance and name for the latest tag of rev'''
221
221
222 cachename = 'latesttags'
222 cachename = 'latesttags'
223 if pattern is not None:
223 if pattern is not None:
224 cachename += '-' + pattern
224 cachename += '-' + pattern
225 match = util.stringmatcher(pattern)[2]
225 match = util.stringmatcher(pattern)[2]
226 else:
226 else:
227 match = util.always
227 match = util.always
228
228
229 if cachename not in cache:
229 if cachename not in cache:
230 # Cache mapping from rev to a tuple with tag date, tag
230 # Cache mapping from rev to a tuple with tag date, tag
231 # distance and tag name
231 # distance and tag name
232 cache[cachename] = {-1: (0, 0, ['null'])}
232 cache[cachename] = {-1: (0, 0, ['null'])}
233 latesttags = cache[cachename]
233 latesttags = cache[cachename]
234
234
235 rev = ctx.rev()
235 rev = ctx.rev()
236 todo = [rev]
236 todo = [rev]
237 while todo:
237 while todo:
238 rev = todo.pop()
238 rev = todo.pop()
239 if rev in latesttags:
239 if rev in latesttags:
240 continue
240 continue
241 ctx = repo[rev]
241 ctx = repo[rev]
242 tags = [t for t in ctx.tags()
242 tags = [t for t in ctx.tags()
243 if (repo.tagtype(t) and repo.tagtype(t) != 'local'
243 if (repo.tagtype(t) and repo.tagtype(t) != 'local'
244 and match(t))]
244 and match(t))]
245 if tags:
245 if tags:
246 latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
246 latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
247 continue
247 continue
248 try:
248 try:
249 ptags = [latesttags[p.rev()] for p in ctx.parents()]
249 ptags = [latesttags[p.rev()] for p in ctx.parents()]
250 if len(ptags) > 1:
250 if len(ptags) > 1:
251 if ptags[0][2] == ptags[1][2]:
251 if ptags[0][2] == ptags[1][2]:
252 # The tuples are laid out so the right one can be found by
252 # The tuples are laid out so the right one can be found by
253 # comparison in this case.
253 # comparison in this case.
254 pdate, pdist, ptag = max(ptags)
254 pdate, pdist, ptag = max(ptags)
255 else:
255 else:
256 def key(x):
256 def key(x):
257 changessincetag = len(repo.revs('only(%d, %s)',
257 changessincetag = len(repo.revs('only(%d, %s)',
258 ctx.rev(), x[2][0]))
258 ctx.rev(), x[2][0]))
259 # Smallest number of changes since tag wins. Date is
259 # Smallest number of changes since tag wins. Date is
260 # used as tiebreaker.
260 # used as tiebreaker.
261 return [-changessincetag, x[0]]
261 return [-changessincetag, x[0]]
262 pdate, pdist, ptag = max(ptags, key=key)
262 pdate, pdist, ptag = max(ptags, key=key)
263 else:
263 else:
264 pdate, pdist, ptag = ptags[0]
264 pdate, pdist, ptag = ptags[0]
265 except KeyError:
265 except KeyError:
266 # Cache miss - recurse
266 # Cache miss - recurse
267 todo.append(rev)
267 todo.append(rev)
268 todo.extend(p.rev() for p in ctx.parents())
268 todo.extend(p.rev() for p in ctx.parents())
269 continue
269 continue
270 latesttags[rev] = pdate, pdist + 1, ptag
270 latesttags[rev] = pdate, pdist + 1, ptag
271 return latesttags[rev]
271 return latesttags[rev]
272
272
273 def getrenamedfn(repo, endrev=None):
273 def getrenamedfn(repo, endrev=None):
274 rcache = {}
274 rcache = {}
275 if endrev is None:
275 if endrev is None:
276 endrev = len(repo)
276 endrev = len(repo)
277
277
278 def getrenamed(fn, rev):
278 def getrenamed(fn, rev):
279 '''looks up all renames for a file (up to endrev) the first
279 '''looks up all renames for a file (up to endrev) the first
280 time the file is given. It indexes on the changerev and only
280 time the file is given. It indexes on the changerev and only
281 parses the manifest if linkrev != changerev.
281 parses the manifest if linkrev != changerev.
282 Returns rename info for fn at changerev rev.'''
282 Returns rename info for fn at changerev rev.'''
283 if fn not in rcache:
283 if fn not in rcache:
284 rcache[fn] = {}
284 rcache[fn] = {}
285 fl = repo.file(fn)
285 fl = repo.file(fn)
286 for i in fl:
286 for i in fl:
287 lr = fl.linkrev(i)
287 lr = fl.linkrev(i)
288 renamed = fl.renamed(fl.node(i))
288 renamed = fl.renamed(fl.node(i))
289 rcache[fn][lr] = renamed
289 rcache[fn][lr] = renamed
290 if lr >= endrev:
290 if lr >= endrev:
291 break
291 break
292 if rev in rcache[fn]:
292 if rev in rcache[fn]:
293 return rcache[fn][rev]
293 return rcache[fn][rev]
294
294
295 # If linkrev != rev (i.e. rev not found in rcache) fallback to
295 # If linkrev != rev (i.e. rev not found in rcache) fallback to
296 # filectx logic.
296 # filectx logic.
297 try:
297 try:
298 return repo[rev][fn].renamed()
298 return repo[rev][fn].renamed()
299 except error.LookupError:
299 except error.LookupError:
300 return None
300 return None
301
301
302 return getrenamed
302 return getrenamed
303
303
304 # default templates internally used for rendering of lists
304 # default templates internally used for rendering of lists
305 defaulttempl = {
305 defaulttempl = {
306 'parent': '{rev}:{node|formatnode} ',
306 'parent': '{rev}:{node|formatnode} ',
307 'manifest': '{rev}:{node|formatnode}',
307 'manifest': '{rev}:{node|formatnode}',
308 'file_copy': '{name} ({source})',
308 'file_copy': '{name} ({source})',
309 'envvar': '{key}={value}',
309 'envvar': '{key}={value}',
310 'extra': '{key}={value|stringescape}'
310 'extra': '{key}={value|stringescape}'
311 }
311 }
312 # filecopy is preserved for compatibility reasons
312 # filecopy is preserved for compatibility reasons
313 defaulttempl['filecopy'] = defaulttempl['file_copy']
313 defaulttempl['filecopy'] = defaulttempl['file_copy']
314
314
315 # keywords are callables like:
315 # keywords are callables like:
316 # fn(repo, ctx, templ, cache, revcache, **args)
316 # fn(repo, ctx, templ, cache, revcache, **args)
317 # with:
317 # with:
318 # repo - current repository instance
318 # repo - current repository instance
319 # ctx - the changectx being displayed
319 # ctx - the changectx being displayed
320 # templ - the templater instance
320 # templ - the templater instance
321 # cache - a cache dictionary for the whole templater run
321 # cache - a cache dictionary for the whole templater run
322 # revcache - a cache dictionary for the current revision
322 # revcache - a cache dictionary for the current revision
323 keywords = {}
323 keywords = {}
324
324
325 templatekeyword = registrar.templatekeyword(keywords)
325 templatekeyword = registrar.templatekeyword(keywords)
326
326
327 @templatekeyword('author')
327 @templatekeyword('author')
328 def showauthor(repo, ctx, templ, **args):
328 def showauthor(repo, ctx, templ, **args):
329 """String. The unmodified author of the changeset."""
329 """String. The unmodified author of the changeset."""
330 return ctx.user()
330 return ctx.user()
331
331
332 @templatekeyword('bisect')
332 @templatekeyword('bisect')
333 def showbisect(repo, ctx, templ, **args):
333 def showbisect(repo, ctx, templ, **args):
334 """String. The changeset bisection status."""
334 """String. The changeset bisection status."""
335 return hbisect.label(repo, ctx.node())
335 return hbisect.label(repo, ctx.node())
336
336
337 @templatekeyword('branch')
337 @templatekeyword('branch')
338 def showbranch(**args):
338 def showbranch(**args):
339 """String. The name of the branch on which the changeset was
339 """String. The name of the branch on which the changeset was
340 committed.
340 committed.
341 """
341 """
342 return args[r'ctx'].branch()
342 return args[r'ctx'].branch()
343
343
344 @templatekeyword('branches')
344 @templatekeyword('branches')
345 def showbranches(**args):
345 def showbranches(**args):
346 """List of strings. The name of the branch on which the
346 """List of strings. The name of the branch on which the
347 changeset was committed. Will be empty if the branch name was
347 changeset was committed. Will be empty if the branch name was
348 default. (DEPRECATED)
348 default. (DEPRECATED)
349 """
349 """
350 args = pycompat.byteskwargs(args)
350 args = pycompat.byteskwargs(args)
351 branch = args['ctx'].branch()
351 branch = args['ctx'].branch()
352 if branch != 'default':
352 if branch != 'default':
353 return showlist('branch', [branch], args, plural='branches')
353 return showlist('branch', [branch], args, plural='branches')
354 return showlist('branch', [], args, plural='branches')
354 return showlist('branch', [], args, plural='branches')
355
355
356 @templatekeyword('bookmarks')
356 @templatekeyword('bookmarks')
357 def showbookmarks(**args):
357 def showbookmarks(**args):
358 """List of strings. Any bookmarks associated with the
358 """List of strings. Any bookmarks associated with the
359 changeset. Also sets 'active', the name of the active bookmark.
359 changeset. Also sets 'active', the name of the active bookmark.
360 """
360 """
361 args = pycompat.byteskwargs(args)
361 args = pycompat.byteskwargs(args)
362 repo = args['ctx']._repo
362 repo = args['ctx']._repo
363 bookmarks = args['ctx'].bookmarks()
363 bookmarks = args['ctx'].bookmarks()
364 active = repo._activebookmark
364 active = repo._activebookmark
365 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
365 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
366 f = _showlist('bookmark', bookmarks, args)
366 f = _showlist('bookmark', bookmarks, args)
367 return _hybrid(f, bookmarks, makemap, pycompat.identity)
367 return _hybrid(f, bookmarks, makemap, pycompat.identity)
368
368
369 @templatekeyword('children')
369 @templatekeyword('children')
370 def showchildren(**args):
370 def showchildren(**args):
371 """List of strings. The children of the changeset."""
371 """List of strings. The children of the changeset."""
372 args = pycompat.byteskwargs(args)
372 args = pycompat.byteskwargs(args)
373 ctx = args['ctx']
373 ctx = args['ctx']
374 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
374 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
375 return showlist('children', childrevs, args, element='child')
375 return showlist('children', childrevs, args, element='child')
376
376
377 # Deprecated, but kept alive for help generation a purpose.
377 # Deprecated, but kept alive for help generation a purpose.
378 @templatekeyword('currentbookmark')
378 @templatekeyword('currentbookmark')
379 def showcurrentbookmark(**args):
379 def showcurrentbookmark(**args):
380 """String. The active bookmark, if it is associated with the changeset.
380 """String. The active bookmark, if it is associated with the changeset.
381 (DEPRECATED)"""
381 (DEPRECATED)"""
382 return showactivebookmark(**args)
382 return showactivebookmark(**args)
383
383
384 @templatekeyword('activebookmark')
384 @templatekeyword('activebookmark')
385 def showactivebookmark(**args):
385 def showactivebookmark(**args):
386 """String. The active bookmark, if it is associated with the changeset."""
386 """String. The active bookmark, if it is associated with the changeset."""
387 active = args[r'repo']._activebookmark
387 active = args[r'repo']._activebookmark
388 if active and active in args[r'ctx'].bookmarks():
388 if active and active in args[r'ctx'].bookmarks():
389 return active
389 return active
390 return ''
390 return ''
391
391
392 @templatekeyword('date')
392 @templatekeyword('date')
393 def showdate(repo, ctx, templ, **args):
393 def showdate(repo, ctx, templ, **args):
394 """Date information. The date when the changeset was committed."""
394 """Date information. The date when the changeset was committed."""
395 return ctx.date()
395 return ctx.date()
396
396
397 @templatekeyword('desc')
397 @templatekeyword('desc')
398 def showdescription(repo, ctx, templ, **args):
398 def showdescription(repo, ctx, templ, **args):
399 """String. The text of the changeset description."""
399 """String. The text of the changeset description."""
400 s = ctx.description()
400 s = ctx.description()
401 if isinstance(s, encoding.localstr):
401 if isinstance(s, encoding.localstr):
402 # try hard to preserve utf-8 bytes
402 # try hard to preserve utf-8 bytes
403 return encoding.tolocal(encoding.fromlocal(s).strip())
403 return encoding.tolocal(encoding.fromlocal(s).strip())
404 else:
404 else:
405 return s.strip()
405 return s.strip()
406
406
407 @templatekeyword('diffstat')
407 @templatekeyword('diffstat')
408 def showdiffstat(repo, ctx, templ, **args):
408 def showdiffstat(repo, ctx, templ, **args):
409 """String. Statistics of changes with the following format:
409 """String. Statistics of changes with the following format:
410 "modified files: +added/-removed lines"
410 "modified files: +added/-removed lines"
411 """
411 """
412 stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False)))
412 stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False)))
413 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
413 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
414 return '%s: +%s/-%s' % (len(stats), adds, removes)
414 return '%s: +%s/-%s' % (len(stats), adds, removes)
415
415
416 @templatekeyword('envvars')
416 @templatekeyword('envvars')
417 def showenvvars(repo, **args):
417 def showenvvars(repo, **args):
418 """A dictionary of environment variables. (EXPERIMENTAL)"""
418 """A dictionary of environment variables. (EXPERIMENTAL)"""
419 args = pycompat.byteskwargs(args)
419 args = pycompat.byteskwargs(args)
420 env = repo.ui.exportableenviron()
420 env = repo.ui.exportableenviron()
421 env = util.sortdict((k, env[k]) for k in sorted(env))
421 env = util.sortdict((k, env[k]) for k in sorted(env))
422 return showdict('envvar', env, args, plural='envvars')
422 return showdict('envvar', env, args, plural='envvars')
423
423
424 @templatekeyword('extras')
424 @templatekeyword('extras')
425 def showextras(**args):
425 def showextras(**args):
426 """List of dicts with key, value entries of the 'extras'
426 """List of dicts with key, value entries of the 'extras'
427 field of this changeset."""
427 field of this changeset."""
428 args = pycompat.byteskwargs(args)
428 args = pycompat.byteskwargs(args)
429 extras = args['ctx'].extra()
429 extras = args['ctx'].extra()
430 extras = util.sortdict((k, extras[k]) for k in sorted(extras))
430 extras = util.sortdict((k, extras[k]) for k in sorted(extras))
431 makemap = lambda k: {'key': k, 'value': extras[k]}
431 makemap = lambda k: {'key': k, 'value': extras[k]}
432 c = [makemap(k) for k in extras]
432 c = [makemap(k) for k in extras]
433 f = _showlist('extra', c, args, plural='extras')
433 f = _showlist('extra', c, args, plural='extras')
434 return _hybrid(f, extras, makemap,
434 return _hybrid(f, extras, makemap,
435 lambda k: '%s=%s' % (k, util.escapestr(extras[k])))
435 lambda k: '%s=%s' % (k, util.escapestr(extras[k])))
436
436
437 @templatekeyword('file_adds')
437 @templatekeyword('file_adds')
438 def showfileadds(**args):
438 def showfileadds(**args):
439 """List of strings. Files added by this changeset."""
439 """List of strings. Files added by this changeset."""
440 args = pycompat.byteskwargs(args)
440 args = pycompat.byteskwargs(args)
441 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
441 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
442 return showlist('file_add', getfiles(repo, ctx, revcache)[1], args,
442 return showlist('file_add', getfiles(repo, ctx, revcache)[1], args,
443 element='file')
443 element='file')
444
444
445 @templatekeyword('file_copies')
445 @templatekeyword('file_copies')
446 def showfilecopies(**args):
446 def showfilecopies(**args):
447 """List of strings. Files copied in this changeset with
447 """List of strings. Files copied in this changeset with
448 their sources.
448 their sources.
449 """
449 """
450 args = pycompat.byteskwargs(args)
450 args = pycompat.byteskwargs(args)
451 cache, ctx = args['cache'], args['ctx']
451 cache, ctx = args['cache'], args['ctx']
452 copies = args['revcache'].get('copies')
452 copies = args['revcache'].get('copies')
453 if copies is None:
453 if copies is None:
454 if 'getrenamed' not in cache:
454 if 'getrenamed' not in cache:
455 cache['getrenamed'] = getrenamedfn(args['repo'])
455 cache['getrenamed'] = getrenamedfn(args['repo'])
456 copies = []
456 copies = []
457 getrenamed = cache['getrenamed']
457 getrenamed = cache['getrenamed']
458 for fn in ctx.files():
458 for fn in ctx.files():
459 rename = getrenamed(fn, ctx.rev())
459 rename = getrenamed(fn, ctx.rev())
460 if rename:
460 if rename:
461 copies.append((fn, rename[0]))
461 copies.append((fn, rename[0]))
462
462
463 copies = util.sortdict(copies)
463 copies = util.sortdict(copies)
464 return showdict('file_copy', copies, args, plural='file_copies',
464 return showdict('file_copy', copies, args, plural='file_copies',
465 key='name', value='source', fmt='%s (%s)')
465 key='name', value='source', fmt='%s (%s)')
466
466
467 # showfilecopiesswitch() displays file copies only if copy records are
467 # showfilecopiesswitch() displays file copies only if copy records are
468 # provided before calling the templater, usually with a --copies
468 # provided before calling the templater, usually with a --copies
469 # command line switch.
469 # command line switch.
470 @templatekeyword('file_copies_switch')
470 @templatekeyword('file_copies_switch')
471 def showfilecopiesswitch(**args):
471 def showfilecopiesswitch(**args):
472 """List of strings. Like "file_copies" but displayed
472 """List of strings. Like "file_copies" but displayed
473 only if the --copied switch is set.
473 only if the --copied switch is set.
474 """
474 """
475 args = pycompat.byteskwargs(args)
475 args = pycompat.byteskwargs(args)
476 copies = args['revcache'].get('copies') or []
476 copies = args['revcache'].get('copies') or []
477 copies = util.sortdict(copies)
477 copies = util.sortdict(copies)
478 return showdict('file_copy', copies, args, plural='file_copies',
478 return showdict('file_copy', copies, args, plural='file_copies',
479 key='name', value='source', fmt='%s (%s)')
479 key='name', value='source', fmt='%s (%s)')
480
480
481 @templatekeyword('file_dels')
481 @templatekeyword('file_dels')
482 def showfiledels(**args):
482 def showfiledels(**args):
483 """List of strings. Files removed by this changeset."""
483 """List of strings. Files removed by this changeset."""
484 args = pycompat.byteskwargs(args)
484 args = pycompat.byteskwargs(args)
485 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
485 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
486 return showlist('file_del', getfiles(repo, ctx, revcache)[2], args,
486 return showlist('file_del', getfiles(repo, ctx, revcache)[2], args,
487 element='file')
487 element='file')
488
488
489 @templatekeyword('file_mods')
489 @templatekeyword('file_mods')
490 def showfilemods(**args):
490 def showfilemods(**args):
491 """List of strings. Files modified by this changeset."""
491 """List of strings. Files modified by this changeset."""
492 args = pycompat.byteskwargs(args)
492 args = pycompat.byteskwargs(args)
493 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
493 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
494 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], args,
494 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], args,
495 element='file')
495 element='file')
496
496
497 @templatekeyword('files')
497 @templatekeyword('files')
498 def showfiles(**args):
498 def showfiles(**args):
499 """List of strings. All files modified, added, or removed by this
499 """List of strings. All files modified, added, or removed by this
500 changeset.
500 changeset.
501 """
501 """
502 args = pycompat.byteskwargs(args)
502 args = pycompat.byteskwargs(args)
503 return showlist('file', args['ctx'].files(), args)
503 return showlist('file', args['ctx'].files(), args)
504
504
505 @templatekeyword('graphnode')
505 @templatekeyword('graphnode')
506 def showgraphnode(repo, ctx, **args):
506 def showgraphnode(repo, ctx, **args):
507 """String. The character representing the changeset node in an ASCII
507 """String. The character representing the changeset node in an ASCII
508 revision graph."""
508 revision graph."""
509 wpnodes = repo.dirstate.parents()
509 wpnodes = repo.dirstate.parents()
510 if wpnodes[1] == nullid:
510 if wpnodes[1] == nullid:
511 wpnodes = wpnodes[:1]
511 wpnodes = wpnodes[:1]
512 if ctx.node() in wpnodes:
512 if ctx.node() in wpnodes:
513 return '@'
513 return '@'
514 elif ctx.obsolete():
514 elif ctx.obsolete():
515 return 'x'
515 return 'x'
516 elif ctx.closesbranch():
516 elif ctx.closesbranch():
517 return '_'
517 return '_'
518 else:
518 else:
519 return 'o'
519 return 'o'
520
520
521 @templatekeyword('graphwidth')
521 @templatekeyword('graphwidth')
522 def showgraphwidth(repo, ctx, templ, **args):
522 def showgraphwidth(repo, ctx, templ, **args):
523 """Integer. The width of the graph drawn by 'log --graph' or zero."""
523 """Integer. The width of the graph drawn by 'log --graph' or zero."""
524 # The value args['graphwidth'] will be this function, so we use an internal
524 # The value args['graphwidth'] will be this function, so we use an internal
525 # name to pass the value through props into this function.
525 # name to pass the value through props into this function.
526 return args.get('_graphwidth', 0)
526 return args.get('_graphwidth', 0)
527
527
528 @templatekeyword('index')
528 @templatekeyword('index')
529 def showindex(**args):
529 def showindex(**args):
530 """Integer. The current iteration of the loop. (0 indexed)"""
530 """Integer. The current iteration of the loop. (0 indexed)"""
531 # just hosts documentation; should be overridden by template mapping
531 # just hosts documentation; should be overridden by template mapping
532 raise error.Abort(_("can't use index in this context"))
532 raise error.Abort(_("can't use index in this context"))
533
533
534 @templatekeyword('latesttag')
534 @templatekeyword('latesttag')
535 def showlatesttag(**args):
535 def showlatesttag(**args):
536 """List of strings. The global tags on the most recent globally
536 """List of strings. The global tags on the most recent globally
537 tagged ancestor of this changeset. If no such tags exist, the list
537 tagged ancestor of this changeset. If no such tags exist, the list
538 consists of the single string "null".
538 consists of the single string "null".
539 """
539 """
540 return showlatesttags(None, **args)
540 return showlatesttags(None, **args)
541
541
542 def showlatesttags(pattern, **args):
542 def showlatesttags(pattern, **args):
543 """helper method for the latesttag keyword and function"""
543 """helper method for the latesttag keyword and function"""
544 args = pycompat.byteskwargs(args)
544 args = pycompat.byteskwargs(args)
545 repo, ctx = args['repo'], args['ctx']
545 repo, ctx = args['repo'], args['ctx']
546 cache = args['cache']
546 cache = args['cache']
547 latesttags = getlatesttags(repo, ctx, cache, pattern)
547 latesttags = getlatesttags(repo, ctx, cache, pattern)
548
548
549 # latesttag[0] is an implementation detail for sorting csets on different
549 # latesttag[0] is an implementation detail for sorting csets on different
550 # branches in a stable manner- it is the date the tagged cset was created,
550 # branches in a stable manner- it is the date the tagged cset was created,
551 # not the date the tag was created. Therefore it isn't made visible here.
551 # not the date the tag was created. Therefore it isn't made visible here.
552 makemap = lambda v: {
552 makemap = lambda v: {
553 'changes': _showchangessincetag,
553 'changes': _showchangessincetag,
554 'distance': latesttags[1],
554 'distance': latesttags[1],
555 'latesttag': v, # BC with {latesttag % '{latesttag}'}
555 'latesttag': v, # BC with {latesttag % '{latesttag}'}
556 'tag': v
556 'tag': v
557 }
557 }
558
558
559 tags = latesttags[2]
559 tags = latesttags[2]
560 f = _showlist('latesttag', tags, args, separator=':')
560 f = _showlist('latesttag', tags, args, separator=':')
561 return _hybrid(f, tags, makemap, pycompat.identity)
561 return _hybrid(f, tags, makemap, pycompat.identity)
562
562
563 @templatekeyword('latesttagdistance')
563 @templatekeyword('latesttagdistance')
564 def showlatesttagdistance(repo, ctx, templ, cache, **args):
564 def showlatesttagdistance(repo, ctx, templ, cache, **args):
565 """Integer. Longest path to the latest tag."""
565 """Integer. Longest path to the latest tag."""
566 return getlatesttags(repo, ctx, cache)[1]
566 return getlatesttags(repo, ctx, cache)[1]
567
567
568 @templatekeyword('changessincelatesttag')
568 @templatekeyword('changessincelatesttag')
569 def showchangessincelatesttag(repo, ctx, templ, cache, **args):
569 def showchangessincelatesttag(repo, ctx, templ, cache, **args):
570 """Integer. All ancestors not in the latest tag."""
570 """Integer. All ancestors not in the latest tag."""
571 latesttag = getlatesttags(repo, ctx, cache)[2][0]
571 latesttag = getlatesttags(repo, ctx, cache)[2][0]
572
572
573 return _showchangessincetag(repo, ctx, tag=latesttag, **args)
573 return _showchangessincetag(repo, ctx, tag=latesttag, **args)
574
574
575 def _showchangessincetag(repo, ctx, **args):
575 def _showchangessincetag(repo, ctx, **args):
576 offset = 0
576 offset = 0
577 revs = [ctx.rev()]
577 revs = [ctx.rev()]
578 tag = args[r'tag']
578 tag = args[r'tag']
579
579
580 # The only() revset doesn't currently support wdir()
580 # The only() revset doesn't currently support wdir()
581 if ctx.rev() is None:
581 if ctx.rev() is None:
582 offset = 1
582 offset = 1
583 revs = [p.rev() for p in ctx.parents()]
583 revs = [p.rev() for p in ctx.parents()]
584
584
585 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset
585 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset
586
586
587 @templatekeyword('manifest')
587 @templatekeyword('manifest')
588 def showmanifest(**args):
588 def showmanifest(**args):
589 repo, ctx, templ = args[r'repo'], args[r'ctx'], args[r'templ']
589 repo, ctx, templ = args[r'repo'], args[r'ctx'], args[r'templ']
590 mnode = ctx.manifestnode()
590 mnode = ctx.manifestnode()
591 if mnode is None:
591 if mnode is None:
592 # just avoid crash, we might want to use the 'ff...' hash in future
592 # just avoid crash, we might want to use the 'ff...' hash in future
593 return
593 return
594 mrev = repo.manifestlog._revlog.rev(mnode)
594 mrev = repo.manifestlog._revlog.rev(mnode)
595 mhex = hex(mnode)
595 mhex = hex(mnode)
596 args = args.copy()
596 args = args.copy()
597 args.update({r'rev': mrev, r'node': mhex})
597 args.update({r'rev': mrev, r'node': mhex})
598 f = templ('manifest', **args)
598 f = templ('manifest', **args)
599 # TODO: perhaps 'ctx' should be dropped from mapping because manifest
599 # TODO: perhaps 'ctx' should be dropped from mapping because manifest
600 # rev and node are completely different from changeset's.
600 # rev and node are completely different from changeset's.
601 return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex})
601 return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex})
602
602
603 def shownames(namespace, **args):
603 def shownames(namespace, **args):
604 """helper method to generate a template keyword for a namespace"""
604 """helper method to generate a template keyword for a namespace"""
605 args = pycompat.byteskwargs(args)
605 args = pycompat.byteskwargs(args)
606 ctx = args['ctx']
606 ctx = args['ctx']
607 repo = ctx.repo()
607 repo = ctx.repo()
608 ns = repo.names[namespace]
608 ns = repo.names[namespace]
609 names = ns.names(repo, ctx.node())
609 names = ns.names(repo, ctx.node())
610 return showlist(ns.templatename, names, args, plural=namespace)
610 return showlist(ns.templatename, names, args, plural=namespace)
611
611
612 @templatekeyword('namespaces')
612 @templatekeyword('namespaces')
613 def shownamespaces(**args):
613 def shownamespaces(**args):
614 """Dict of lists. Names attached to this changeset per
614 """Dict of lists. Names attached to this changeset per
615 namespace."""
615 namespace."""
616 args = pycompat.byteskwargs(args)
616 args = pycompat.byteskwargs(args)
617 ctx = args['ctx']
617 ctx = args['ctx']
618 repo = ctx.repo()
618 repo = ctx.repo()
619
619
620 namespaces = util.sortdict()
620 namespaces = util.sortdict()
621 def makensmapfn(ns):
621 def makensmapfn(ns):
622 # 'name' for iterating over namespaces, templatename for local reference
622 # 'name' for iterating over namespaces, templatename for local reference
623 return lambda v: {'name': v, ns.templatename: v}
623 return lambda v: {'name': v, ns.templatename: v}
624
624
625 for k, ns in repo.names.iteritems():
625 for k, ns in repo.names.iteritems():
626 names = ns.names(repo, ctx.node())
626 names = ns.names(repo, ctx.node())
627 f = _showlist('name', names, args)
627 f = _showlist('name', names, args)
628 namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity)
628 namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity)
629
629
630 f = _showlist('namespace', list(namespaces), args)
630 f = _showlist('namespace', list(namespaces), args)
631
631
632 def makemap(ns):
632 def makemap(ns):
633 return {
633 return {
634 'namespace': ns,
634 'namespace': ns,
635 'names': namespaces[ns],
635 'names': namespaces[ns],
636 'builtin': repo.names[ns].builtin,
636 'builtin': repo.names[ns].builtin,
637 'colorname': repo.names[ns].colorname,
637 'colorname': repo.names[ns].colorname,
638 }
638 }
639
639
640 return _hybrid(f, namespaces, makemap, pycompat.identity)
640 return _hybrid(f, namespaces, makemap, pycompat.identity)
641
641
642 @templatekeyword('node')
642 @templatekeyword('node')
643 def shownode(repo, ctx, templ, **args):
643 def shownode(repo, ctx, templ, **args):
644 """String. The changeset identification hash, as a 40 hexadecimal
644 """String. The changeset identification hash, as a 40 hexadecimal
645 digit string.
645 digit string.
646 """
646 """
647 return ctx.hex()
647 return ctx.hex()
648
648
649 @templatekeyword('obsolete')
649 @templatekeyword('obsolete')
650 def showobsolete(repo, ctx, templ, **args):
650 def showobsolete(repo, ctx, templ, **args):
651 """String. Whether the changeset is obsolete.
651 """String. Whether the changeset is obsolete. (EXPERIMENTAL)"""
652 """
653 if ctx.obsolete():
652 if ctx.obsolete():
654 return 'obsolete'
653 return 'obsolete'
655 return ''
654 return ''
656
655
657 @templatekeyword('peerurls')
656 @templatekeyword('peerurls')
658 def showpeerurls(repo, **args):
657 def showpeerurls(repo, **args):
659 """A dictionary of repository locations defined in the [paths] section
658 """A dictionary of repository locations defined in the [paths] section
660 of your configuration file."""
659 of your configuration file."""
661 # see commands.paths() for naming of dictionary keys
660 # see commands.paths() for naming of dictionary keys
662 paths = repo.ui.paths
661 paths = repo.ui.paths
663 urls = util.sortdict((k, p.rawloc) for k, p in sorted(paths.iteritems()))
662 urls = util.sortdict((k, p.rawloc) for k, p in sorted(paths.iteritems()))
664 def makemap(k):
663 def makemap(k):
665 p = paths[k]
664 p = paths[k]
666 d = {'name': k, 'url': p.rawloc}
665 d = {'name': k, 'url': p.rawloc}
667 d.update((o, v) for o, v in sorted(p.suboptions.iteritems()))
666 d.update((o, v) for o, v in sorted(p.suboptions.iteritems()))
668 return d
667 return d
669 return _hybrid(None, urls, makemap, lambda k: '%s=%s' % (k, urls[k]))
668 return _hybrid(None, urls, makemap, lambda k: '%s=%s' % (k, urls[k]))
670
669
671 @templatekeyword("predecessors")
670 @templatekeyword("predecessors")
672 def showpredecessors(repo, ctx, **args):
671 def showpredecessors(repo, ctx, **args):
673 """Returns the list if the closest visible successors."""
672 """Returns the list if the closest visible successors. (EXPERIMENTAL)"""
674 predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node()))
673 predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node()))
675 predecessors = map(hex, predecessors)
674 predecessors = map(hex, predecessors)
676
675
677 return _hybrid(None, predecessors,
676 return _hybrid(None, predecessors,
678 lambda x: {'ctx': repo[x], 'revcache': {}},
677 lambda x: {'ctx': repo[x], 'revcache': {}},
679 lambda x: scmutil.formatchangeid(repo[x]))
678 lambda x: scmutil.formatchangeid(repo[x]))
680
679
681 @templatekeyword("successorssets")
680 @templatekeyword("successorssets")
682 def showsuccessorssets(repo, ctx, **args):
681 def showsuccessorssets(repo, ctx, **args):
683 """Returns a string of sets of successors for a changectx. Format used
682 """Returns a string of sets of successors for a changectx. Format used
684 is: [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and ctx2
683 is: [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and ctx2
685 while also diverged into ctx3."""
684 while also diverged into ctx3. (EXPERIMENTAL)"""
686 if not ctx.obsolete():
685 if not ctx.obsolete():
687 return ''
686 return ''
688 args = pycompat.byteskwargs(args)
687 args = pycompat.byteskwargs(args)
689
688
690 ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
689 ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
691 ssets = [[hex(n) for n in ss] for ss in ssets]
690 ssets = [[hex(n) for n in ss] for ss in ssets]
692
691
693 data = []
692 data = []
694 for ss in ssets:
693 for ss in ssets:
695 h = _hybrid(None, ss, lambda x: {'ctx': repo[x], 'revcache': {}},
694 h = _hybrid(None, ss, lambda x: {'ctx': repo[x], 'revcache': {}},
696 lambda x: scmutil.formatchangeid(repo[x]))
695 lambda x: scmutil.formatchangeid(repo[x]))
697 data.append(h)
696 data.append(h)
698
697
699 # Format the successorssets
698 # Format the successorssets
700 def render(d):
699 def render(d):
701 t = []
700 t = []
702 for i in d.gen():
701 for i in d.gen():
703 t.append(i)
702 t.append(i)
704 return "".join(t)
703 return "".join(t)
705
704
706 def gen(data):
705 def gen(data):
707 yield "; ".join(render(d) for d in data)
706 yield "; ".join(render(d) for d in data)
708
707
709 return _hybrid(gen(data), data, lambda x: {'successorset': x},
708 return _hybrid(gen(data), data, lambda x: {'successorset': x},
710 pycompat.identity)
709 pycompat.identity)
711
710
712 @templatekeyword("succsandmarkers")
711 @templatekeyword("succsandmarkers")
713 def showsuccsandmarkers(repo, ctx, **args):
712 def showsuccsandmarkers(repo, ctx, **args):
714 """Returns a list of dict for each final successor of ctx. The dict
713 """Returns a list of dict for each final successor of ctx. The dict
715 contains successors node id in "successors" keys and the list of
714 contains successors node id in "successors" keys and the list of
716 obs-markers from ctx to the set of successors in "markers".
715 obs-markers from ctx to the set of successors in "markers".
717 (EXPERIMENTAL)
716 (EXPERIMENTAL)
718 """
717 """
719
718
720 values = obsutil.successorsandmarkers(repo, ctx)
719 values = obsutil.successorsandmarkers(repo, ctx)
721
720
722 if values is None:
721 if values is None:
723 values = []
722 values = []
724
723
725 # Format successors and markers to avoid exposing binary to templates
724 # Format successors and markers to avoid exposing binary to templates
726 data = []
725 data = []
727 for i in values:
726 for i in values:
728 # Format successors
727 # Format successors
729 successors = i['successors']
728 successors = i['successors']
730
729
731 successors = [hex(n) for n in successors]
730 successors = [hex(n) for n in successors]
732 successors = _hybrid(None, successors,
731 successors = _hybrid(None, successors,
733 lambda x: {'ctx': repo[x], 'revcache': {}},
732 lambda x: {'ctx': repo[x], 'revcache': {}},
734 lambda x: scmutil.formatchangeid(repo[x]))
733 lambda x: scmutil.formatchangeid(repo[x]))
735
734
736 # Format markers
735 # Format markers
737 finalmarkers = []
736 finalmarkers = []
738 for m in i['markers']:
737 for m in i['markers']:
739 hexprec = hex(m[0])
738 hexprec = hex(m[0])
740 hexsucs = tuple(hex(n) for n in m[1])
739 hexsucs = tuple(hex(n) for n in m[1])
741 hexparents = None
740 hexparents = None
742 if m[5] is not None:
741 if m[5] is not None:
743 hexparents = tuple(hex(n) for n in m[5])
742 hexparents = tuple(hex(n) for n in m[5])
744 newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:]
743 newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:]
745 finalmarkers.append(newmarker)
744 finalmarkers.append(newmarker)
746
745
747 data.append({'successors': successors, 'markers': finalmarkers})
746 data.append({'successors': successors, 'markers': finalmarkers})
748
747
749 f = _showlist('succsandmarkers', data, args)
748 f = _showlist('succsandmarkers', data, args)
750 return _hybrid(f, data, lambda x: x, pycompat.identity)
749 return _hybrid(f, data, lambda x: x, pycompat.identity)
751
750
752 @templatekeyword('p1rev')
751 @templatekeyword('p1rev')
753 def showp1rev(repo, ctx, templ, **args):
752 def showp1rev(repo, ctx, templ, **args):
754 """Integer. The repository-local revision number of the changeset's
753 """Integer. The repository-local revision number of the changeset's
755 first parent, or -1 if the changeset has no parents."""
754 first parent, or -1 if the changeset has no parents."""
756 return ctx.p1().rev()
755 return ctx.p1().rev()
757
756
758 @templatekeyword('p2rev')
757 @templatekeyword('p2rev')
759 def showp2rev(repo, ctx, templ, **args):
758 def showp2rev(repo, ctx, templ, **args):
760 """Integer. The repository-local revision number of the changeset's
759 """Integer. The repository-local revision number of the changeset's
761 second parent, or -1 if the changeset has no second parent."""
760 second parent, or -1 if the changeset has no second parent."""
762 return ctx.p2().rev()
761 return ctx.p2().rev()
763
762
764 @templatekeyword('p1node')
763 @templatekeyword('p1node')
765 def showp1node(repo, ctx, templ, **args):
764 def showp1node(repo, ctx, templ, **args):
766 """String. The identification hash of the changeset's first parent,
765 """String. The identification hash of the changeset's first parent,
767 as a 40 digit hexadecimal string. If the changeset has no parents, all
766 as a 40 digit hexadecimal string. If the changeset has no parents, all
768 digits are 0."""
767 digits are 0."""
769 return ctx.p1().hex()
768 return ctx.p1().hex()
770
769
771 @templatekeyword('p2node')
770 @templatekeyword('p2node')
772 def showp2node(repo, ctx, templ, **args):
771 def showp2node(repo, ctx, templ, **args):
773 """String. The identification hash of the changeset's second
772 """String. The identification hash of the changeset's second
774 parent, as a 40 digit hexadecimal string. If the changeset has no second
773 parent, as a 40 digit hexadecimal string. If the changeset has no second
775 parent, all digits are 0."""
774 parent, all digits are 0."""
776 return ctx.p2().hex()
775 return ctx.p2().hex()
777
776
778 @templatekeyword('parents')
777 @templatekeyword('parents')
779 def showparents(**args):
778 def showparents(**args):
780 """List of strings. The parents of the changeset in "rev:node"
779 """List of strings. The parents of the changeset in "rev:node"
781 format. If the changeset has only one "natural" parent (the predecessor
780 format. If the changeset has only one "natural" parent (the predecessor
782 revision) nothing is shown."""
781 revision) nothing is shown."""
783 args = pycompat.byteskwargs(args)
782 args = pycompat.byteskwargs(args)
784 repo = args['repo']
783 repo = args['repo']
785 ctx = args['ctx']
784 ctx = args['ctx']
786 pctxs = scmutil.meaningfulparents(repo, ctx)
785 pctxs = scmutil.meaningfulparents(repo, ctx)
787 prevs = [p.rev() for p in pctxs]
786 prevs = [p.rev() for p in pctxs]
788 parents = [[('rev', p.rev()),
787 parents = [[('rev', p.rev()),
789 ('node', p.hex()),
788 ('node', p.hex()),
790 ('phase', p.phasestr())]
789 ('phase', p.phasestr())]
791 for p in pctxs]
790 for p in pctxs]
792 f = _showlist('parent', parents, args)
791 f = _showlist('parent', parents, args)
793 return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}},
792 return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}},
794 lambda x: scmutil.formatchangeid(repo[x]), keytype=int)
793 lambda x: scmutil.formatchangeid(repo[x]), keytype=int)
795
794
796 @templatekeyword('phase')
795 @templatekeyword('phase')
797 def showphase(repo, ctx, templ, **args):
796 def showphase(repo, ctx, templ, **args):
798 """String. The changeset phase name."""
797 """String. The changeset phase name."""
799 return ctx.phasestr()
798 return ctx.phasestr()
800
799
801 @templatekeyword('phaseidx')
800 @templatekeyword('phaseidx')
802 def showphaseidx(repo, ctx, templ, **args):
801 def showphaseidx(repo, ctx, templ, **args):
803 """Integer. The changeset phase index."""
802 """Integer. The changeset phase index."""
804 return ctx.phase()
803 return ctx.phase()
805
804
806 @templatekeyword('rev')
805 @templatekeyword('rev')
807 def showrev(repo, ctx, templ, **args):
806 def showrev(repo, ctx, templ, **args):
808 """Integer. The repository-local changeset revision number."""
807 """Integer. The repository-local changeset revision number."""
809 return scmutil.intrev(ctx)
808 return scmutil.intrev(ctx)
810
809
811 def showrevslist(name, revs, **args):
810 def showrevslist(name, revs, **args):
812 """helper to generate a list of revisions in which a mapped template will
811 """helper to generate a list of revisions in which a mapped template will
813 be evaluated"""
812 be evaluated"""
814 args = pycompat.byteskwargs(args)
813 args = pycompat.byteskwargs(args)
815 repo = args['ctx'].repo()
814 repo = args['ctx'].repo()
816 f = _showlist(name, ['%d' % r for r in revs], args)
815 f = _showlist(name, ['%d' % r for r in revs], args)
817 return _hybrid(f, revs,
816 return _hybrid(f, revs,
818 lambda x: {name: x, 'ctx': repo[x], 'revcache': {}},
817 lambda x: {name: x, 'ctx': repo[x], 'revcache': {}},
819 pycompat.identity, keytype=int)
818 pycompat.identity, keytype=int)
820
819
821 @templatekeyword('subrepos')
820 @templatekeyword('subrepos')
822 def showsubrepos(**args):
821 def showsubrepos(**args):
823 """List of strings. Updated subrepositories in the changeset."""
822 """List of strings. Updated subrepositories in the changeset."""
824 args = pycompat.byteskwargs(args)
823 args = pycompat.byteskwargs(args)
825 ctx = args['ctx']
824 ctx = args['ctx']
826 substate = ctx.substate
825 substate = ctx.substate
827 if not substate:
826 if not substate:
828 return showlist('subrepo', [], args)
827 return showlist('subrepo', [], args)
829 psubstate = ctx.parents()[0].substate or {}
828 psubstate = ctx.parents()[0].substate or {}
830 subrepos = []
829 subrepos = []
831 for sub in substate:
830 for sub in substate:
832 if sub not in psubstate or substate[sub] != psubstate[sub]:
831 if sub not in psubstate or substate[sub] != psubstate[sub]:
833 subrepos.append(sub) # modified or newly added in ctx
832 subrepos.append(sub) # modified or newly added in ctx
834 for sub in psubstate:
833 for sub in psubstate:
835 if sub not in substate:
834 if sub not in substate:
836 subrepos.append(sub) # removed in ctx
835 subrepos.append(sub) # removed in ctx
837 return showlist('subrepo', sorted(subrepos), args)
836 return showlist('subrepo', sorted(subrepos), args)
838
837
839 # don't remove "showtags" definition, even though namespaces will put
838 # don't remove "showtags" definition, even though namespaces will put
840 # a helper function for "tags" keyword into "keywords" map automatically,
839 # a helper function for "tags" keyword into "keywords" map automatically,
841 # because online help text is built without namespaces initialization
840 # because online help text is built without namespaces initialization
842 @templatekeyword('tags')
841 @templatekeyword('tags')
843 def showtags(**args):
842 def showtags(**args):
844 """List of strings. Any tags associated with the changeset."""
843 """List of strings. Any tags associated with the changeset."""
845 return shownames('tags', **args)
844 return shownames('tags', **args)
846
845
847 def loadkeyword(ui, extname, registrarobj):
846 def loadkeyword(ui, extname, registrarobj):
848 """Load template keyword from specified registrarobj
847 """Load template keyword from specified registrarobj
849 """
848 """
850 for name, func in registrarobj._table.iteritems():
849 for name, func in registrarobj._table.iteritems():
851 keywords[name] = func
850 keywords[name] = func
852
851
853 @templatekeyword('termwidth')
852 @templatekeyword('termwidth')
854 def showtermwidth(repo, ctx, templ, **args):
853 def showtermwidth(repo, ctx, templ, **args):
855 """Integer. The width of the current terminal."""
854 """Integer. The width of the current terminal."""
856 return repo.ui.termwidth()
855 return repo.ui.termwidth()
857
856
858 @templatekeyword('troubles')
857 @templatekeyword('troubles')
859 def showtroubles(repo, **args):
858 def showtroubles(repo, **args):
860 """List of strings. Evolution troubles affecting the changeset.
859 """List of strings. Evolution troubles affecting the changeset.
861 (DEPRECATED)
860 (DEPRECATED)
862 """
861 """
863 msg = ("'troubles' is deprecated, "
862 msg = ("'troubles' is deprecated, "
864 "use 'instabilities'")
863 "use 'instabilities'")
865 repo.ui.deprecwarn(msg, '4.4')
864 repo.ui.deprecwarn(msg, '4.4')
866
865
867 return showinstabilities(repo=repo, **args)
866 return showinstabilities(repo=repo, **args)
868
867
869 @templatekeyword('instabilities')
868 @templatekeyword('instabilities')
870 def showinstabilities(**args):
869 def showinstabilities(**args):
871 """List of strings. Evolution instabilities affecting the changeset.
870 """List of strings. Evolution instabilities affecting the changeset.
872 (EXPERIMENTAL)
871 (EXPERIMENTAL)
873 """
872 """
874 args = pycompat.byteskwargs(args)
873 args = pycompat.byteskwargs(args)
875 return showlist('instability', args['ctx'].instabilities(), args,
874 return showlist('instability', args['ctx'].instabilities(), args,
876 plural='instabilities')
875 plural='instabilities')
877
876
878 # tell hggettext to extract docstrings from these functions:
877 # tell hggettext to extract docstrings from these functions:
879 i18nfunctions = keywords.values()
878 i18nfunctions = keywords.values()
General Comments 0
You need to be logged in to leave comments. Login now