##// END OF EJS Templates
templating: make new-style templating features work with command line lists
Matt Mackall -
r17631:0b241d7a default
parent child Browse files
Show More
@@ -9,7 +9,27 b' from node import hex'
9 import patch, util, error
9 import patch, util, error
10 import hbisect
10 import hbisect
11
11
12 def showlist(name, values, plural=None, **args):
12 # This helper class allows us to handle both:
13 # "{files}" (legacy command-line-specific list hack) and
14 # "{files % '{file}\n'}" (hgweb-style with inlining and function support)
15
16 class _hybrid(object):
17 def __init__(self, gen, values):
18 self.gen = gen
19 self.values = values
20 def __iter__(self):
21 return self.gen
22 def __call__(self):
23 for x in self.values:
24 yield x
25
26 def showlist(name, values, plural=None, element=None, **args):
27 if not element:
28 element = name
29 f = _showlist(name, values, plural, **args)
30 return _hybrid(f, [{element: x} for x in values])
31
32 def _showlist(name, values, plural=None, **args):
13 '''expand set of values.
33 '''expand set of values.
14 name is name of key in template map.
34 name is name of key in template map.
15 values is list of strings or dicts.
35 values is list of strings or dicts.
@@ -176,7 +196,7 b' def showchildren(**args):'
176 """:children: List of strings. The children of the changeset."""
196 """:children: List of strings. The children of the changeset."""
177 ctx = args['ctx']
197 ctx = args['ctx']
178 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
198 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
179 return showlist('children', childrevs, **args)
199 return showlist('children', childrevs, element='child', **args)
180
200
181 def showdate(repo, ctx, templ, **args):
201 def showdate(repo, ctx, templ, **args):
182 """:date: Date information. The date when the changeset was committed."""
202 """:date: Date information. The date when the changeset was committed."""
@@ -204,7 +224,8 b' def showextras(**args):'
204 def showfileadds(**args):
224 def showfileadds(**args):
205 """:file_adds: List of strings. Files added by this changeset."""
225 """:file_adds: List of strings. Files added by this changeset."""
206 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
226 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
207 return showlist('file_add', getfiles(repo, ctx, revcache)[1], **args)
227 return showlist('file_add', getfiles(repo, ctx, revcache)[1],
228 element='file', **args)
208
229
209 def showfilecopies(**args):
230 def showfilecopies(**args):
210 """:file_copies: List of strings. Files copied in this changeset with
231 """:file_copies: List of strings. Files copied in this changeset with
@@ -223,7 +244,8 b' def showfilecopies(**args):'
223 copies.append((fn, rename[0]))
244 copies.append((fn, rename[0]))
224
245
225 c = [{'name': x[0], 'source': x[1]} for x in copies]
246 c = [{'name': x[0], 'source': x[1]} for x in copies]
226 return showlist('file_copy', c, plural='file_copies', **args)
247 return showlist('file_copy', c, plural='file_copies',
248 element='file', **args)
227
249
228 # showfilecopiesswitch() displays file copies only if copy records are
250 # showfilecopiesswitch() displays file copies only if copy records are
229 # provided before calling the templater, usually with a --copies
251 # provided before calling the templater, usually with a --copies
@@ -234,17 +256,20 b' def showfilecopiesswitch(**args):'
234 """
256 """
235 copies = args['revcache'].get('copies') or []
257 copies = args['revcache'].get('copies') or []
236 c = [{'name': x[0], 'source': x[1]} for x in copies]
258 c = [{'name': x[0], 'source': x[1]} for x in copies]
237 return showlist('file_copy', c, plural='file_copies', **args)
259 return showlist('file_copy', c, plural='file_copies',
260 element='file', **args)
238
261
239 def showfiledels(**args):
262 def showfiledels(**args):
240 """:file_dels: List of strings. Files removed by this changeset."""
263 """:file_dels: List of strings. Files removed by this changeset."""
241 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
264 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
242 return showlist('file_del', getfiles(repo, ctx, revcache)[2], **args)
265 return showlist('file_del', getfiles(repo, ctx, revcache)[2],
266 element='file', **args)
243
267
244 def showfilemods(**args):
268 def showfilemods(**args):
245 """:file_mods: List of strings. Files modified by this changeset."""
269 """:file_mods: List of strings. Files modified by this changeset."""
246 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
270 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
247 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], **args)
271 return showlist('file_mod', getfiles(repo, ctx, revcache)[0],
272 element='file', **args)
248
273
249 def showfiles(**args):
274 def showfiles(**args):
250 """:files: List of strings. All files modified, added, or removed by this
275 """:files: List of strings. All files modified, added, or removed by this
@@ -164,6 +164,9 b' def buildmap(exp, context):'
164 def runmap(context, mapping, data):
164 def runmap(context, mapping, data):
165 func, data, ctmpl = data
165 func, data, ctmpl = data
166 d = func(context, mapping, data)
166 d = func(context, mapping, data)
167 if util.safehasattr(d, '__call__'):
168 d = d()
169
167 lm = mapping.copy()
170 lm = mapping.copy()
168
171
169 for i in d:
172 for i in d:
@@ -1520,3 +1520,8 b' Test recursive showlist template (issue1'
1520 10,test
1520 10,test
1521 branch: test
1521 branch: test
1522
1522
1523 Test new-style inline templating:
1524
1525 $ hg log -R latesttag -r tip --template 'modified files: {file_mods % " {file}\n"}\n'
1526 modified files: .hgtags
1527
General Comments 0
You need to be logged in to leave comments. Login now