Mercurial > hg
diff mercurial/templater.py @ 37102:638a241202a3
templater: add hook point to populate additional mapping items
The 'revcache' dict will be inserted by this hook.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 15 Mar 2018 21:49:33 +0900 |
parents | f0b6fbea00cf |
children | 888507ec655e |
line wrap: on
line diff
--- a/mercurial/templater.py Sat Mar 24 01:30:50 2018 -0400 +++ b/mercurial/templater.py Thu Mar 15 21:49:33 2018 +0900 @@ -577,6 +577,11 @@ def lookup(self, context, mapping, key): """Return a resource for the key if available; otherwise None""" + @abc.abstractmethod + def populatemap(self, context, origmapping, newmapping): + """Return a dict of additional mapping items which should be paired + with the given new mapping""" + class nullresourcemapper(resourcemapper): def availablekeys(self, context, mapping): return set() @@ -587,6 +592,9 @@ def lookup(self, context, mapping, key): return None + def populatemap(self, context, origmapping, newmapping): + return {} + class engine(object): '''template expansion engine. @@ -634,6 +642,8 @@ if (k in knownres # not a symbol per self.symbol() or newres.isdisjoint(self._defaultrequires(k)))} mapping.update(newmapping) + mapping.update( + self._resources.populatemap(self, origmapping, newmapping)) return mapping def _defaultrequires(self, key): @@ -689,6 +699,13 @@ mapping contains added elements for use during expansion. Is a generator.''' func, data = self._load(t) + # populate additional items only if they don't exist in the given + # mapping. this is slightly different from overlaymap() because the + # initial 'revcache' may contain pre-computed items. + extramapping = self._resources.populatemap(self, {}, mapping) + if extramapping: + extramapping.update(mapping) + mapping = extramapping return _flatten(func(self, mapping, data)) engines = {'default': engine}