Mercurial > public > mercurial-scm > hg-stable
diff mercurial/formatter.py @ 35473:f1c54d003327
templater: move repo, ui and cache to per-engine resources
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 21 Dec 2017 22:05:30 +0900 |
parents | 32c278eb876f |
children | a33be093ec62 |
line wrap: on
line diff
--- a/mercurial/formatter.py Thu Dec 21 21:29:06 2017 +0900 +++ b/mercurial/formatter.py Thu Dec 21 22:05:30 2017 +0900 @@ -363,11 +363,11 @@ self._out = out spec = lookuptemplate(ui, topic, opts.get('template', '')) self._tref = spec.ref - self._t = loadtemplater(ui, spec, cache=templatekw.defaulttempl) + self._t = loadtemplater(ui, spec, resources=templateresources(ui), + cache=templatekw.defaulttempl) self._parts = templatepartsmap(spec, self._t, ['docheader', 'docfooter', 'separator']) self._counter = itertools.count() - self._cache = {} # for templatekw/funcs to store reusable data self._renderitem('docheader', {}) def _showitem(self): @@ -395,7 +395,7 @@ props['repo'] = props['ctx'].repo() props['revcache'] = {} props = pycompat.strkwargs(props) - g = self._t(ref, ui=self._ui, cache=self._cache, **props) + g = self._t(ref, **props) self._out.write(templater.stringify(g)) def end(self): @@ -486,6 +486,15 @@ t.cache[''] = tmpl return t +def templateresources(ui, repo=None): + """Create a dict of template resources designed for the default templatekw + and function""" + return { + 'cache': {}, # for templatekw/funcs to store reusable data + 'repo': repo, + 'ui': ui, + } + def formatter(ui, out, topic, opts): template = opts.get("template", "") if template == "json":