comparison mercurial/formatter.py @ 39624:713085b45810

formatter: replace contexthint() with demand loading of ctx object And pass in repo instead to resolve ctx from (repo, node) pair.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 01 Sep 2018 15:52:18 +0900
parents 34ecc0a09c76
children 46f9b1d2daf0
comparison
equal deleted inserted replaced
39623:34ecc0a09c76 39624:713085b45810
122 122
123 from . import ( 123 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,
131 util, 130 util,
132 ) 131 )
191 def formatlist(self, data, name, fmt=None, sep=' '): 190 def formatlist(self, data, name, fmt=None, sep=' '):
192 '''convert iterable to appropriate list format''' 191 '''convert iterable to appropriate list format'''
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)
202 assert all(k in {'repo', 'ctx', 'fctx'} for k in ctxs) 198 assert all(k in {'repo', 'ctx', 'fctx'} for k in ctxs)
203 if self._converter.storecontext: 199 if self._converter.storecontext:
425 421
426 @util.propertycache 422 @util.propertycache
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]
451 429
452 def end(self): 430 def end(self):