##// 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 def _printbookmarks(ui, repo, bmarks, **
923 """
923 """
924 opts = pycompat.byteskwargs(opts)
924 opts = pycompat.byteskwargs(opts)
925 fm = ui.formatter('bookmarks', opts)
925 fm = ui.formatter('bookmarks', opts)
926 contexthint = fm.contexthint('bookmark rev node active')
927 hexfn = fm.hexfunc
926 hexfn = fm.hexfunc
928 if len(bmarks) == 0 and fm.isplain():
927 if len(bmarks) == 0 and fm.isplain():
929 ui.status(_("no bookmarks set\n"))
928 ui.status(_("no bookmarks set\n"))
930 for bmark, (n, prefix, label) in sorted(bmarks.iteritems()):
929 for bmark, (n, prefix, label) in sorted(bmarks.iteritems()):
931 fm.startitem()
930 fm.startitem()
932 if 'ctx' in contexthint:
931 fm.context(repo=repo)
933 fm.context(ctx=repo[n])
934 if not ui.quiet:
932 if not ui.quiet:
935 fm.plain(' %s ' % prefix, label=label)
933 fm.plain(' %s ' % prefix, label=label)
936 fm.write('bookmark', '%s', bmark, label=label)
934 fm.write('bookmark', '%s', bmark, label=label)
@@ -5639,7 +5639,6 def tags(ui, repo, **opts):
5639 opts = pycompat.byteskwargs(opts)
5639 opts = pycompat.byteskwargs(opts)
5640 ui.pager('tags')
5640 ui.pager('tags')
5641 fm = ui.formatter('tags', opts)
5641 fm = ui.formatter('tags', opts)
5642 contexthint = fm.contexthint('tag rev node type')
5643 hexfunc = fm.hexfunc
5642 hexfunc = fm.hexfunc
5644 tagtype = ""
5643 tagtype = ""
5645
5644
@@ -5652,8 +5651,7 def tags(ui, repo, **opts):
5652 tagtype = 'local'
5651 tagtype = 'local'
5653
5652
5654 fm.startitem()
5653 fm.startitem()
5655 if 'ctx' in contexthint:
5654 fm.context(repo=repo)
5656 fm.context(ctx=repo[n])
5657 fm.write('tag', '%s', t, label=label)
5655 fm.write('tag', '%s', t, label=label)
5658 fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s'
5656 fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s'
5659 fm.condwrite(not ui.quiet, 'rev node', fmt,
5657 fm.condwrite(not ui.quiet, 'rev node', fmt,
@@ -124,7 +124,6 from . import (
124 error,
124 error,
125 pycompat,
125 pycompat,
126 templatefilters,
126 templatefilters,
127 templatefuncs,
128 templatekw,
127 templatekw,
129 templater,
128 templater,
130 templateutil,
129 templateutil,
@@ -193,9 +192,6 class baseformatter(object):
193 # name is mandatory argument for now, but it could be optional if
192 # name is mandatory argument for now, but it could be optional if
194 # we have default template keyword, e.g. {item}
193 # we have default template keyword, e.g. {item}
195 return self._converter.formatlist(data, name, fmt, sep)
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 def context(self, **ctxs):
195 def context(self, **ctxs):
200 '''insert context objects to be used to render template keywords'''
196 '''insert context objects to be used to render template keywords'''
201 ctxs = pycompat.byteskwargs(ctxs)
197 ctxs = pycompat.byteskwargs(ctxs)
@@ -427,24 +423,6 class templateformatter(baseformatter):
427 def _symbolsused(self):
423 def _symbolsused(self):
428 return self._t.symbolsused(self._tref)
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 def datahint(self):
426 def datahint(self):
449 '''set of field names to be referenced from the template'''
427 '''set of field names to be referenced from the template'''
450 return self._symbolsused[0]
428 return self._symbolsused[0]
General Comments 0
You need to be logged in to leave comments. Login now