changeset 39584:109b2c2d9942

formatter: inline _gettermap and _knownkeys
author Yuya Nishihara <yuya@tcha.org>
date Sat, 01 Sep 2018 15:06:05 +0900
parents ee1e74ee037c
children 990a0b071ea5
files mercurial/formatter.py
diffstat 1 files changed, 5 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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":