diff --git a/mercurial/formatter.py b/mercurial/formatter.py --- a/mercurial/formatter.py +++ b/mercurial/formatter.py @@ -401,9 +401,7 @@ class templateformatter(baseformatter): if 'ctx' in item or 'fctx' in item: # but template resources must be always available props['revcache'] = {} - props = pycompat.strkwargs(props) - g = self._t(ref, **props) - self._out.write(templateutil.stringify(g)) + self._out.write(self._t.render(ref, props)) def end(self): baseformatter.end(self) diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -30,7 +30,6 @@ from .. import ( repoview, templatefilters, templater, - templateutil, ui as uimod, util, wireprotoserver, @@ -378,8 +377,8 @@ class hgweb(object): try: rctx.tmpl = rctx.templater(req) - ctype = rctx.tmpl('mimetype', encoding=encoding.encoding) - ctype = templateutil.stringify(ctype) + ctype = rctx.tmpl.render('mimetype', + {'encoding': encoding.encoding}) # check read permissions non-static content if cmd != 'static': diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -35,7 +35,6 @@ from .. import ( pycompat, scmutil, templater, - templateutil, ui as uimod, util, ) @@ -381,8 +380,7 @@ class hgwebdir(object): virtual = req.dispatchpath.strip('/') tmpl = self.templater(req, nonce) - ctype = tmpl('mimetype', encoding=encoding.encoding) - ctype = templateutil.stringify(ctype) + ctype = tmpl.render('mimetype', {'encoding': encoding.encoding}) # Global defaults. These can be overridden by any handler. res.status = '200 Script output follows' diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py --- a/mercurial/logcmdutil.py +++ b/mercurial/logcmdutil.py @@ -33,7 +33,6 @@ from . import ( smartset, templatekw, templater, - templateutil, util, ) from .utils import dateutil @@ -450,15 +449,13 @@ class changesettemplater(changesetprinte self._parts.update(m) if self._parts['docheader']: - self.ui.write( - templateutil.stringify(self.t(self._parts['docheader']))) + self.ui.write(self.t.render(self._parts['docheader'], {})) def close(self): if self._parts['docfooter']: if not self.footer: self.footer = "" - self.footer += templateutil.stringify( - self.t(self._parts['docfooter'])) + self.footer += self.t.render(self._parts['docfooter'], {}) return super(changesettemplater, self).close() def _show(self, ctx, copies, props): @@ -467,18 +464,16 @@ class changesettemplater(changesetprinte props['ctx'] = ctx props['index'] = index = next(self._counter) props['revcache'] = {'copies': copies} - props = pycompat.strkwargs(props) # write separator, which wouldn't work well with the header part below # since there's inherently a conflict between header (across items) and # separator (per item) if self._parts['separator'] and index > 0: - self.ui.write( - templateutil.stringify(self.t(self._parts['separator']))) + self.ui.write(self.t.render(self._parts['separator'], {})) # write header if self._parts['header']: - h = templateutil.stringify(self.t(self._parts['header'], **props)) + h = self.t.render(self._parts['header'], props) if self.buffered: self.header[ctx.rev()] = h else: @@ -488,13 +483,12 @@ class changesettemplater(changesetprinte # write changeset metadata, then patch if requested key = self._parts[self._tref] - self.ui.write(templateutil.stringify(self.t(key, **props))) + self.ui.write(self.t.render(key, props)) self._showpatch(ctx) if self._parts['footer']: if not self.footer: - self.footer = templateutil.stringify( - self.t(self._parts['footer'], **props)) + self.footer = self.t.render(self._parts['footer'], props) def templatespec(tmpl, mapfile): if mapfile: diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -725,8 +725,12 @@ class templater(object): def renderdefault(self, mapping): """Render the default unnamed template and return result as string""" + return self.render('', mapping) + + def render(self, t, mapping): + """Render the specified named template and return result as string""" mapping = pycompat.strkwargs(mapping) - return templateutil.stringify(self('', **mapping)) + return templateutil.stringify(self(t, **mapping)) def __call__(self, t, **mapping): mapping = pycompat.byteskwargs(mapping)