formatter: inline _gettermap and _knownkeys
authorYuya Nishihara <yuya@tcha.org>
Sat, 01 Sep 2018 15:06:05 +0900
changeset 39584 109b2c2d9942
parent 39583 ee1e74ee037c
child 39585 990a0b071ea5
formatter: inline _gettermap and _knownkeys
mercurial/formatter.py
--- a/mercurial/formatter.py	Sat Sep 01 13:21:45 2018 +0900
+++ b/mercurial/formatter.py	Sat Sep 01 15:06:05 2018 +0900
@@ -554,17 +554,16 @@
         }
 
     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 @@
     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":