comparison mercurial/logcmdutil.py @ 36982:255f635c3204

templater: convert resources to a table of callables for future extension I'm going to add a full templating support to the annotate command. As the annotate is a filectx-oriented command, we'll need a way to look up a ctx from a bounded fctx only when necessary. This is the minimal change to support that. I'm thinking of defining a proper interface to look up template resources to fix other issues, but that isn't ready yet. (Changes from V1: just updated tests and patch descriptions.)
author Yuya Nishihara <yuya@tcha.org>
date Sun, 11 Mar 2018 21:05:29 +0900
parents 6ff6e1d6b5b8
children 317382151ac3
comparison
equal deleted inserted replaced
36978:c479692690ef 36982:255f635c3204
421 self.t = formatter.loadtemplater(ui, tmplspec, 421 self.t = formatter.loadtemplater(ui, tmplspec,
422 defaults=templatekw.keywords, 422 defaults=templatekw.keywords,
423 resources=tres, 423 resources=tres,
424 cache=templatekw.defaulttempl) 424 cache=templatekw.defaulttempl)
425 self._counter = itertools.count() 425 self._counter = itertools.count()
426 self.cache = tres['cache'] # shared with _graphnodeformatter() 426 self._getcache = tres['cache'] # shared with _graphnodeformatter()
427 427
428 self._tref = tmplspec.ref 428 self._tref = tmplspec.ref
429 self._parts = {'header': '', 'footer': '', 429 self._parts = {'header': '', 'footer': '',
430 tmplspec.ref: tmplspec.ref, 430 tmplspec.ref: tmplspec.ref,
431 'docheader': '', 'docfooter': '', 431 'docheader': '', 'docfooter': '',
850 return templatekw.getgraphnode # fast path for "{graphnode}" 850 return templatekw.getgraphnode # fast path for "{graphnode}"
851 851
852 spec = templater.unquotestring(spec) 852 spec = templater.unquotestring(spec)
853 tres = formatter.templateresources(ui) 853 tres = formatter.templateresources(ui)
854 if isinstance(displayer, changesettemplater): 854 if isinstance(displayer, changesettemplater):
855 tres['cache'] = displayer.cache # reuse cache of slow templates 855 # reuse cache of slow templates
856 tres['cache'] = displayer._getcache
856 templ = formatter.maketemplater(ui, spec, defaults=templatekw.keywords, 857 templ = formatter.maketemplater(ui, spec, defaults=templatekw.keywords,
857 resources=tres) 858 resources=tres)
858 def formatnode(repo, ctx): 859 def formatnode(repo, ctx):
859 props = {'ctx': ctx, 'repo': repo, 'revcache': {}} 860 props = {'ctx': ctx, 'repo': repo, 'revcache': {}}
860 return templ.render(props) 861 return templ.render(props)