##// END OF EJS Templates
templater: use template context to render old-style list template...
Yuya Nishihara -
r37086:aa97e06a default
parent child Browse files
Show More
@@ -356,12 +356,11 b' def lfsfileset(mctx, x):'
356 356 return [f for f in mctx.subset
357 357 if wrapper.pointerfromctx(mctx.ctx, f, removed=True) is not None]
358 358
359 @templatekeyword('lfs_files', requires={'ctx', 'templ'})
359 @templatekeyword('lfs_files', requires={'ctx'})
360 360 def lfsfiles(context, mapping):
361 361 """List of strings. All files modified, added, or removed by this
362 362 changeset."""
363 363 ctx = context.resource(mapping, 'ctx')
364 templ = context.resource(mapping, 'templ')
365 364
366 365 pointers = wrapper.pointersfromctx(ctx, removed=True) # {path: pointer}
367 366 files = sorted(pointers.keys())
@@ -379,7 +378,7 b' def lfsfiles(context, mapping):'
379 378 }
380 379
381 380 # TODO: make the separator ', '?
382 f = templateutil._showlist('lfs_file', files, templ, mapping)
381 f = templateutil._showcompatlist(context, mapping, 'lfs_file', files)
383 382 return templateutil.hybrid(f, files, makemap, pycompat.identity)
384 383
385 384 @command('debuglfsupload',
@@ -230,7 +230,7 b' def reposetup(ui, repo):'
230 230 repo._remotenames.nodetobranch().get(node, []))
231 231 repo.names.addnamespace(remotebranchns)
232 232
233 @templatekeyword('remotenames', requires={'repo', 'ctx', 'templ'})
233 @templatekeyword('remotenames', requires={'repo', 'ctx'})
234 234 def remotenameskw(context, mapping):
235 235 """List of strings. Remote names associated with the changeset."""
236 236 repo = context.resource(mapping, 'repo')
@@ -246,7 +246,7 b' def remotenameskw(context, mapping):'
246 246 return templateutil.compatlist(context, mapping, 'remotename', remotenames,
247 247 plural='remotenames')
248 248
249 @templatekeyword('remotebookmarks', requires={'repo', 'ctx', 'templ'})
249 @templatekeyword('remotebookmarks', requires={'repo', 'ctx'})
250 250 def remotebookmarkskw(context, mapping):
251 251 """List of strings. Remote bookmarks associated with the changeset."""
252 252 repo = context.resource(mapping, 'repo')
@@ -259,7 +259,7 b' def remotebookmarkskw(context, mapping):'
259 259 return templateutil.compatlist(context, mapping, 'remotebookmark',
260 260 remotebmarks, plural='remotebookmarks')
261 261
262 @templatekeyword('remotebranches', requires={'repo', 'ctx', 'templ'})
262 @templatekeyword('remotebranches', requires={'repo', 'ctx'})
263 263 def remotebrancheskw(context, mapping):
264 264 """List of strings. Remote branches associated with the changeset."""
265 265 repo = context.resource(mapping, 'repo')
@@ -89,7 +89,7 b' class namespaces(object):'
89 89 # we only generate a template keyword if one does not already exist
90 90 if namespace.name not in templatekw.keywords:
91 91 templatekeyword = registrar.templatekeyword(templatekw.keywords)
92 @templatekeyword(namespace.name, requires={'repo', 'ctx', 'templ'})
92 @templatekeyword(namespace.name, requires={'repo', 'ctx'})
93 93 def generatekw(context, mapping):
94 94 return templatekw.shownames(context, mapping, namespace.name)
95 95
@@ -29,11 +29,26 b' from . import ('
29 29
30 30 _hybrid = templateutil.hybrid
31 31 _mappable = templateutil.mappable
32 _showlist = templateutil._showlist
33 32 hybriddict = templateutil.hybriddict
34 33 hybridlist = templateutil.hybridlist
35 34 compatdict = templateutil.compatdict
36 35 compatlist = templateutil.compatlist
36 _showcompatlist = templateutil._showcompatlist
37
38 # TODO: temporary hack for porting; will be removed soon
39 class _fakecontextwrapper(object):
40 def __init__(self, templ):
41 self._templ = templ
42
43 def preload(self, t):
44 return t in self._templ
45
46 def process(self, t, mapping):
47 return self._templ.generatenamed(t, mapping)
48
49 def _showlist(name, values, templ, mapping, plural=None, separator=' '):
50 context = _fakecontextwrapper(templ)
51 return _showcompatlist(context, mapping, name, values, plural, separator)
37 52
38 53 def showdict(name, data, mapping, plural=None, key='key', value='value',
39 54 fmt=None, separator=' '):
@@ -203,7 +218,7 b' def showbranch(context, mapping):'
203 218 ctx = context.resource(mapping, 'ctx')
204 219 return ctx.branch()
205 220
206 @templatekeyword('branches', requires={'ctx', 'templ'})
221 @templatekeyword('branches', requires={'ctx'})
207 222 def showbranches(context, mapping):
208 223 """List of strings. The name of the branch on which the
209 224 changeset was committed. Will be empty if the branch name was
@@ -230,7 +245,7 b' def showbookmarks(context, mapping):'
230 245 f = _showlist('bookmark', bookmarks, templ, mapping)
231 246 return _hybrid(f, bookmarks, makemap, pycompat.identity)
232 247
233 @templatekeyword('children', requires={'ctx', 'templ'})
248 @templatekeyword('children', requires={'ctx'})
234 249 def showchildren(context, mapping):
235 250 """List of strings. The children of the changeset."""
236 251 ctx = context.resource(mapping, 'ctx')
@@ -281,7 +296,7 b' def showdiffstat(context, mapping):'
281 296 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
282 297 return '%d: +%d/-%d' % (len(stats), adds, removes)
283 298
284 @templatekeyword('envvars', requires={'ui', 'templ'})
299 @templatekeyword('envvars', requires={'ui'})
285 300 def showenvvars(context, mapping):
286 301 """A dictionary of environment variables. (EXPERIMENTAL)"""
287 302 ui = context.resource(mapping, 'ui')
@@ -312,13 +327,13 b' def _showfilesbystat(context, mapping, n'
312 327 files = revcache['files'][index]
313 328 return compatlist(context, mapping, name, files, element='file')
314 329
315 @templatekeyword('file_adds', requires={'repo', 'ctx', 'revcache', 'templ'})
330 @templatekeyword('file_adds', requires={'repo', 'ctx', 'revcache'})
316 331 def showfileadds(context, mapping):
317 332 """List of strings. Files added by this changeset."""
318 333 return _showfilesbystat(context, mapping, 'file_add', 1)
319 334
320 335 @templatekeyword('file_copies',
321 requires={'repo', 'ctx', 'cache', 'revcache', 'templ'})
336 requires={'repo', 'ctx', 'cache', 'revcache'})
322 337 def showfilecopies(context, mapping):
323 338 """List of strings. Files copied in this changeset with
324 339 their sources.
@@ -345,7 +360,7 b' def showfilecopies(context, mapping):'
345 360 # showfilecopiesswitch() displays file copies only if copy records are
346 361 # provided before calling the templater, usually with a --copies
347 362 # command line switch.
348 @templatekeyword('file_copies_switch', requires={'revcache', 'templ'})
363 @templatekeyword('file_copies_switch', requires={'revcache'})
349 364 def showfilecopiesswitch(context, mapping):
350 365 """List of strings. Like "file_copies" but displayed
351 366 only if the --copied switch is set.
@@ -356,17 +371,17 b' def showfilecopiesswitch(context, mappin'
356 371 key='name', value='source', fmt='%s (%s)',
357 372 plural='file_copies')
358 373
359 @templatekeyword('file_dels', requires={'repo', 'ctx', 'revcache', 'templ'})
374 @templatekeyword('file_dels', requires={'repo', 'ctx', 'revcache'})
360 375 def showfiledels(context, mapping):
361 376 """List of strings. Files removed by this changeset."""
362 377 return _showfilesbystat(context, mapping, 'file_del', 2)
363 378
364 @templatekeyword('file_mods', requires={'repo', 'ctx', 'revcache', 'templ'})
379 @templatekeyword('file_mods', requires={'repo', 'ctx', 'revcache'})
365 380 def showfilemods(context, mapping):
366 381 """List of strings. Files modified by this changeset."""
367 382 return _showfilesbystat(context, mapping, 'file_mod', 0)
368 383
369 @templatekeyword('files', requires={'ctx', 'templ'})
384 @templatekeyword('files', requires={'ctx'})
370 385 def showfiles(context, mapping):
371 386 """List of strings. All files modified, added, or removed by this
372 387 changeset.
@@ -465,11 +480,10 b' def _showchangessincetag(context, mappin'
465 480 # teach templater latesttags.changes is switched to (context, mapping) API
466 481 _showchangessincetag._requires = {'repo', 'ctx'}
467 482
468 @templatekeyword('manifest', requires={'repo', 'ctx', 'templ'})
483 @templatekeyword('manifest', requires={'repo', 'ctx'})
469 484 def showmanifest(context, mapping):
470 485 repo = context.resource(mapping, 'repo')
471 486 ctx = context.resource(mapping, 'ctx')
472 templ = context.resource(mapping, 'templ')
473 487 mnode = ctx.manifestnode()
474 488 if mnode is None:
475 489 # just avoid crash, we might want to use the 'ff...' hash in future
@@ -478,7 +492,7 b' def showmanifest(context, mapping):'
478 492 mhex = hex(mnode)
479 493 mapping = mapping.copy()
480 494 mapping.update({'rev': mrev, 'node': mhex})
481 f = templ.generate('manifest', mapping)
495 f = context.process('manifest', mapping)
482 496 # TODO: perhaps 'ctx' should be dropped from mapping because manifest
483 497 # rev and node are completely different from changeset's.
484 498 return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex})
@@ -738,7 +752,7 b' def showrevslist(context, mapping, name,'
738 752 lambda x: {name: x, 'ctx': repo[x], 'revcache': {}},
739 753 pycompat.identity, keytype=int)
740 754
741 @templatekeyword('subrepos', requires={'ctx', 'templ'})
755 @templatekeyword('subrepos', requires={'ctx'})
742 756 def showsubrepos(context, mapping):
743 757 """List of strings. Updated subrepositories in the changeset."""
744 758 ctx = context.resource(mapping, 'ctx')
@@ -758,7 +772,7 b' def showsubrepos(context, mapping):'
758 772 # don't remove "showtags" definition, even though namespaces will put
759 773 # a helper function for "tags" keyword into "keywords" map automatically,
760 774 # because online help text is built without namespaces initialization
761 @templatekeyword('tags', requires={'repo', 'ctx', 'templ'})
775 @templatekeyword('tags', requires={'repo', 'ctx'})
762 776 def showtags(context, mapping):
763 777 """List of strings. Any tags associated with the changeset."""
764 778 return shownames(context, mapping, 'tags')
@@ -769,7 +783,7 b' def showtermwidth(context, mapping):'
769 783 ui = context.resource(mapping, 'ui')
770 784 return ui.termwidth()
771 785
772 @templatekeyword('instabilities', requires={'ctx', 'templ'})
786 @templatekeyword('instabilities', requires={'ctx'})
773 787 def showinstabilities(context, mapping):
774 788 """List of strings. Evolution instabilities affecting the changeset.
775 789 (EXPERIMENTAL)
@@ -148,8 +148,7 b' def compatdict(context, mapping, name, d'
148 148 hybriddict() for new template keywords.
149 149 """
150 150 c = [{key: k, value: v} for k, v in data.iteritems()]
151 t = context.resource(mapping, 'templ')
152 f = _showlist(name, c, t, mapping, plural, separator)
151 f = _showcompatlist(context, mapping, name, c, plural, separator)
153 152 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
154 153
155 154 def compatlist(context, mapping, name, data, element=None, fmt=None,
@@ -159,12 +158,12 b' def compatlist(context, mapping, name, d'
159 158 This exists for backward compatibility with the old-style template. Use
160 159 hybridlist() for new template keywords.
161 160 """
162 t = context.resource(mapping, 'templ')
163 f = _showlist(name, data, t, mapping, plural, separator)
161 f = _showcompatlist(context, mapping, name, data, plural, separator)
164 162 return hybridlist(data, name=element or name, fmt=fmt, gen=f)
165 163
166 def _showlist(name, values, templ, mapping, plural=None, separator=' '):
167 '''expand set of values.
164 def _showcompatlist(context, mapping, name, values, plural=None, separator=' '):
165 """Return a generator that renders old-style list template
166
168 167 name is name of key in template map.
169 168 values is list of strings or dicts.
170 169 plural is plural of name, if not simply name + 's'.
@@ -183,15 +182,15 b' def _showlist(name, values, templ, mappi'
183 182 map, expand it instead of 'foo' for last key.
184 183
185 184 expand 'end_foos'.
186 '''
185 """
187 186 if not plural:
188 187 plural = name + 's'
189 188 if not values:
190 189 noname = 'no_' + plural
191 if noname in templ:
192 yield templ.generate(noname, mapping)
190 if context.preload(noname):
191 yield context.process(noname, mapping)
193 192 return
194 if name not in templ:
193 if not context.preload(name):
195 194 if isinstance(values[0], bytes):
196 195 yield separator.join(values)
197 196 else:
@@ -201,8 +200,8 b' def _showlist(name, values, templ, mappi'
201 200 yield r
202 201 return
203 202 startname = 'start_' + plural
204 if startname in templ:
205 yield templ.generate(startname, mapping)
203 if context.preload(startname):
204 yield context.process(startname, mapping)
206 205 vmapping = mapping.copy()
207 206 def one(v, tag=name):
208 207 try:
@@ -217,9 +216,9 b' def _showlist(name, values, templ, mappi'
217 216 vmapping[a] = b
218 217 except (TypeError, ValueError):
219 218 vmapping[name] = v
220 return templ.generate(tag, vmapping)
219 return context.process(tag, vmapping)
221 220 lastname = 'last_' + name
222 if lastname in templ:
221 if context.preload(lastname):
223 222 last = values.pop()
224 223 else:
225 224 last = None
@@ -228,8 +227,8 b' def _showlist(name, values, templ, mappi'
228 227 if last is not None:
229 228 yield one(last, tag=lastname)
230 229 endname = 'end_' + plural
231 if endname in templ:
232 yield templ.generate(endname, mapping)
230 if context.preload(endname):
231 yield context.process(endname, mapping)
233 232
234 233 def stringify(thing):
235 234 """Turn values into bytes by converting into text and concatenating them"""
General Comments 0
You need to be logged in to leave comments. Login now