[PATCH 3 of 6] formatter: inline _gettermap and _knownkeys
Yuya Nishihara
yuya at tcha.org
Sun Sep 2 03:43:00 EDT 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1535781965 -32400
# Sat Sep 01 15:06:05 2018 +0900
# Node ID a7705bfb43080a977945aa42bec757b5ee88216c
# Parent 84b86965ea131a83ad7b4a5adaad04b337a138b5
formatter: inline _gettermap and _knownkeys
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":
More information about the Mercurial-devel
mailing list