Patchwork [6,of,9] log: do no expect templateresources() returning a dict

login
register
mail settings
Submitter Yuya Nishihara
Date March 21, 2018, 1:51 p.m.
Message ID <9355c9249336741a1ac8.1521640314@mimosa>
Download mbox | patch
Permalink /patch/29692/
State Accepted
Headers show

Comments

Yuya Nishihara - March 21, 2018, 1:51 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1521113258 -32400
#      Thu Mar 15 20:27:38 2018 +0900
# Node ID 9355c9249336741a1ac80c33788608a3349184ee
# Parent  a348ff11094fab5fb2ca565eef4333c92d8d70d5
log: do no expect templateresources() returning a dict

The resources dict will be replaced with new resource mapper object, which
won't implement __getitem__(key). Share the whole resources object with
_graphnodeformater() to make porting easier.

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -416,13 +416,13 @@  class changesettemplater(changesetprinte
     def __init__(self, ui, repo, tmplspec, differ=None, diffopts=None,
                  buffered=False):
         changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered)
-        tres = formatter.templateresources(ui, repo)
+        # tres is shared with _graphnodeformatter()
+        self._tresources = tres = formatter.templateresources(ui, repo)
         self.t = formatter.loadtemplater(ui, tmplspec,
                                          defaults=templatekw.keywords,
                                          resources=tres,
                                          cache=templatekw.defaulttempl)
         self._counter = itertools.count()
-        self._getcache = tres['cache']  # shared with _graphnodeformatter()
 
         self._tref = tmplspec.ref
         self._parts = {'header': '', 'footer': '',
@@ -844,10 +844,11 @@  def _graphnodeformatter(ui, displayer):
         return templatekw.getgraphnode  # fast path for "{graphnode}"
 
     spec = templater.unquotestring(spec)
-    tres = formatter.templateresources(ui)
     if isinstance(displayer, changesettemplater):
         # reuse cache of slow templates
-        tres['cache'] = displayer._getcache
+        tres = displayer._tresources
+    else:
+        tres = formatter.templateresources(ui)
     templ = formatter.maketemplater(ui, spec, defaults=templatekw.keywords,
                                     resources=tres)
     def formatnode(repo, ctx):