Patchwork [6,of,8] formatter: provide hint of referenced field names

login
register
mail settings
Submitter Yuya Nishihara
Date June 14, 2018, 3:40 p.m.
Message ID <b330c4cff0bd57e21e4c.1528990831@mimosa>
Download mbox | patch
Permalink /patch/32136/
State Accepted
Headers show

Comments

Yuya Nishihara - June 14, 2018, 3:40 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1525316209 -32400
#      Thu May 03 11:56:49 2018 +0900
# Node ID b330c4cff0bd57e21e4ca08ef18b8f7e512741a6
# Parent  92efa37a0696007f5445c6cd69a395fb2e1cdd5f
formatter: provide hint of referenced field names

I don't like the function name, but I call it datahint() for consistency
with another function I'll add later, fm.contexthint().

Patch

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -198,6 +198,9 @@  class baseformatter(object):
         assert all(k in {'ctx', 'fctx'} for k in ctxs)
         if self._converter.storecontext:
             self._item.update(ctxs)
+    def datahint(self):
+        '''set of field names to be referenced'''
+        return set()
     def data(self, **data):
         '''insert data into item that's not shown in default output'''
         data = pycompat.byteskwargs(data)
@@ -411,6 +414,14 @@  class templateformatter(baseformatter):
         ref = self._parts[part]
         self._out.write(self._t.render(ref, item))
 
+    @util.propertycache
+    def _symbolsused(self):
+        return self._t.symbolsuseddefault()
+
+    def datahint(self):
+        '''set of field names to be referenced from the template'''
+        return self._symbolsused[0]
+
     def end(self):
         baseformatter.end(self)
         self._renderitem('docfooter', {})