--- 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":