##// END OF EJS Templates
formatter: replace contexthint() with demand loading of ctx object...
Yuya Nishihara -
r39660:713085b4 default
parent child Browse files
Show More
@@ -923,14 +923,12 b' def _printbookmarks(ui, repo, bmarks, **'
923 923 """
924 924 opts = pycompat.byteskwargs(opts)
925 925 fm = ui.formatter('bookmarks', opts)
926 contexthint = fm.contexthint('bookmark rev node active')
927 926 hexfn = fm.hexfunc
928 927 if len(bmarks) == 0 and fm.isplain():
929 928 ui.status(_("no bookmarks set\n"))
930 929 for bmark, (n, prefix, label) in sorted(bmarks.iteritems()):
931 930 fm.startitem()
932 if 'ctx' in contexthint:
933 fm.context(ctx=repo[n])
931 fm.context(repo=repo)
934 932 if not ui.quiet:
935 933 fm.plain(' %s ' % prefix, label=label)
936 934 fm.write('bookmark', '%s', bmark, label=label)
@@ -5639,7 +5639,6 b' def tags(ui, repo, **opts):'
5639 5639 opts = pycompat.byteskwargs(opts)
5640 5640 ui.pager('tags')
5641 5641 fm = ui.formatter('tags', opts)
5642 contexthint = fm.contexthint('tag rev node type')
5643 5642 hexfunc = fm.hexfunc
5644 5643 tagtype = ""
5645 5644
@@ -5652,8 +5651,7 b' def tags(ui, repo, **opts):'
5652 5651 tagtype = 'local'
5653 5652
5654 5653 fm.startitem()
5655 if 'ctx' in contexthint:
5656 fm.context(ctx=repo[n])
5654 fm.context(repo=repo)
5657 5655 fm.write('tag', '%s', t, label=label)
5658 5656 fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s'
5659 5657 fm.condwrite(not ui.quiet, 'rev node', fmt,
@@ -124,7 +124,6 b' from . import ('
124 124 error,
125 125 pycompat,
126 126 templatefilters,
127 templatefuncs,
128 127 templatekw,
129 128 templater,
130 129 templateutil,
@@ -193,9 +192,6 b' class baseformatter(object):'
193 192 # name is mandatory argument for now, but it could be optional if
194 193 # we have default template keyword, e.g. {item}
195 194 return self._converter.formatlist(data, name, fmt, sep)
196 def contexthint(self, datafields):
197 '''set of context object keys to be required given datafields set'''
198 return set()
199 195 def context(self, **ctxs):
200 196 '''insert context objects to be used to render template keywords'''
201 197 ctxs = pycompat.byteskwargs(ctxs)
@@ -427,24 +423,6 b' class templateformatter(baseformatter):'
427 423 def _symbolsused(self):
428 424 return self._t.symbolsused(self._tref)
429 425
430 def contexthint(self, datafields):
431 '''set of context object keys to be required by the template, given
432 datafields overridden by immediate values'''
433 requires = set()
434 ksyms, fsyms = self._symbolsused
435 ksyms = ksyms - set(datafields.split()) # exclude immediate fields
436 symtables = [(ksyms, templatekw.keywords),
437 (fsyms, templatefuncs.funcs)]
438 for syms, table in symtables:
439 for k in syms:
440 f = table.get(k)
441 if not f:
442 continue
443 requires.update(getattr(f, '_requires', ()))
444 if 'repo' in requires:
445 requires.add('ctx') # there's no API to pass repo to formatter
446 return requires & {'ctx', 'fctx'}
447
448 426 def datahint(self):
449 427 '''set of field names to be referenced from the template'''
450 428 return self._symbolsused[0]
General Comments 0
You need to be logged in to leave comments. Login now