Patchwork [3,of,6] formatter: inline _gettermap and _knownkeys

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 2, 2018, 7:43 a.m.
Message ID <a7705bfb43080a977945.1535874180@mimosa>
Download mbox | patch
Permalink /patch/34248/
State New
Headers show

Comments

Yuya Nishihara - Sept. 2, 2018, 7:43 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1535781965 -32400
#      Sat Sep 01 15:06:05 2018 +0900
# Node ID a7705bfb43080a977945aa42bec757b5ee88216c
# Parent  84b86965ea131a83ad7b4a5adaad04b337a138b5
formatter: inline _gettermap and _knownkeys

Patch

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -554,17 +554,16 @@  class templateresources(templater.resour
         }
 
     def availablekeys(self, mapping):
-        return {k for k, g in self._gettermap.iteritems()
-                if g(self, mapping, k) is not None}
+        return {k for k in self.knownkeys()
+                if self._getsome(mapping, k) is not None}
 
     def knownkeys(self):
-        return self._knownkeys
+        return {'cache', 'ctx', 'fctx', 'repo', 'revcache', 'ui'}
 
     def lookup(self, mapping, key):
-        get = self._gettermap.get(key)
-        if not get:
+        if key not in self.knownkeys():
             return None
-        return get(self, mapping, key)
+        return self._getsome(mapping, key)
 
     def populatemap(self, context, origmapping, newmapping):
         mapping = {}
@@ -585,16 +584,6 @@  class templateresources(templater.resour
     def _hasctx(self, mapping):
         return 'ctx' in mapping
 
-    _gettermap = {
-        'cache': _getsome,
-        'ctx': _getsome,
-        'fctx': _getsome,
-        'repo': _getsome,
-        'revcache': _getsome,
-        'ui': _getsome,
-    }
-    _knownkeys = set(_gettermap.keys())
-
 def formatter(ui, out, topic, opts):
     template = opts.get("template", "")
     if template == "json":