Patchwork [2,of,4] formatter: replace contexthint() with demand loading of ctx object

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 14, 2018, 2 p.m.
Message ID <1ad0f7146d0ef9d3d84c.1536933622@mimosa>
Download mbox | patch
Permalink /patch/34643/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 14, 2018, 2 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1535784738 -32400
#      Sat Sep 01 15:52:18 2018 +0900
# Node ID 1ad0f7146d0ef9d3d84c431f2c5dab67602c5083
# Parent  04148415f749c0c0345af335ce2d55ba8168e380
formatter: replace contexthint() with demand loading of ctx object

And pass in repo instead to resolve ctx from (repo, node) pair.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -923,14 +923,12 @@  def _printbookmarks(ui, repo, bmarks, **
     """
     opts = pycompat.byteskwargs(opts)
     fm = ui.formatter('bookmarks', opts)
-    contexthint = fm.contexthint('bookmark rev node active')
     hexfn = fm.hexfunc
     if len(bmarks) == 0 and fm.isplain():
         ui.status(_("no bookmarks set\n"))
     for bmark, (n, prefix, label) in sorted(bmarks.iteritems()):
         fm.startitem()
-        if 'ctx' in contexthint:
-            fm.context(ctx=repo[n])
+        fm.context(repo=repo)
         if not ui.quiet:
             fm.plain(' %s ' % prefix, label=label)
         fm.write('bookmark', '%s', bmark, label=label)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5639,7 +5639,6 @@  def tags(ui, repo, **opts):
     opts = pycompat.byteskwargs(opts)
     ui.pager('tags')
     fm = ui.formatter('tags', opts)
-    contexthint = fm.contexthint('tag rev node type')
     hexfunc = fm.hexfunc
     tagtype = ""
 
@@ -5652,8 +5651,7 @@  def tags(ui, repo, **opts):
             tagtype = 'local'
 
         fm.startitem()
-        if 'ctx' in contexthint:
-            fm.context(ctx=repo[n])
+        fm.context(repo=repo)
         fm.write('tag', '%s', t, label=label)
         fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s'
         fm.condwrite(not ui.quiet, 'rev node', fmt,
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -124,7 +124,6 @@  from . import (
     error,
     pycompat,
     templatefilters,
-    templatefuncs,
     templatekw,
     templater,
     templateutil,
@@ -193,9 +192,6 @@  class baseformatter(object):
         # name is mandatory argument for now, but it could be optional if
         # we have default template keyword, e.g. {item}
         return self._converter.formatlist(data, name, fmt, sep)
-    def contexthint(self, datafields):
-        '''set of context object keys to be required given datafields set'''
-        return set()
     def context(self, **ctxs):
         '''insert context objects to be used to render template keywords'''
         ctxs = pycompat.byteskwargs(ctxs)
@@ -427,24 +423,6 @@  class templateformatter(baseformatter):
     def _symbolsused(self):
         return self._t.symbolsused(self._tref)
 
-    def contexthint(self, datafields):
-        '''set of context object keys to be required by the template, given
-        datafields overridden by immediate values'''
-        requires = set()
-        ksyms, fsyms = self._symbolsused
-        ksyms = ksyms - set(datafields.split())  # exclude immediate fields
-        symtables = [(ksyms, templatekw.keywords),
-                     (fsyms, templatefuncs.funcs)]
-        for syms, table in symtables:
-            for k in syms:
-                f = table.get(k)
-                if not f:
-                    continue
-                requires.update(getattr(f, '_requires', ()))
-        if 'repo' in requires:
-            requires.add('ctx')  # there's no API to pass repo to formatter
-        return requires & {'ctx', 'fctx'}
-
     def datahint(self):
         '''set of field names to be referenced from the template'''
         return self._symbolsused[0]