mercurial/templater.py
changeset 37398 3235afdfcf1c
parent 37272 7d3bc1d4e871
child 37399 0b64416224d9
equal deleted inserted replaced
37397:46d9f998c3ed 37398:3235afdfcf1c
   601             resources = nullresourcemapper()
   601             resources = nullresourcemapper()
   602         self._defaults = defaults
   602         self._defaults = defaults
   603         self._resources = resources
   603         self._resources = resources
   604         self._aliasmap = _aliasrules.buildmap(aliases)
   604         self._aliasmap = _aliasrules.buildmap(aliases)
   605         self._cache = {}  # key: (func, data)
   605         self._cache = {}  # key: (func, data)
       
   606         self._tmplcache = {}  # literal template: (func, data)
   606 
   607 
   607     def overlaymap(self, origmapping, newmapping):
   608     def overlaymap(self, origmapping, newmapping):
   608         """Create combined mapping from the original mapping and partial
   609         """Create combined mapping from the original mapping and partial
   609         mapping to override the original"""
   610         mapping to override the original"""
   610         # do not copy symbols which overrides the defaults depending on
   611         # do not copy symbols which overrides the defaults depending on
   657             except: # re-raises
   658             except: # re-raises
   658                 del self._cache[t]
   659                 del self._cache[t]
   659                 raise
   660                 raise
   660         return self._cache[t]
   661         return self._cache[t]
   661 
   662 
       
   663     def _parse(self, tmpl):
       
   664         """Parse and cache a literal template"""
       
   665         if tmpl not in self._tmplcache:
       
   666             x = parse(tmpl)
       
   667             self._tmplcache[tmpl] = compileexp(x, self, methods)
       
   668         return self._tmplcache[tmpl]
       
   669 
   662     def preload(self, t):
   670     def preload(self, t):
   663         """Load, parse, and cache the specified template if available"""
   671         """Load, parse, and cache the specified template if available"""
   664         try:
   672         try:
   665             self._load(t)
   673             self._load(t)
   666             return True
   674             return True
   670     def process(self, t, mapping):
   678     def process(self, t, mapping):
   671         '''Perform expansion. t is name of map element to expand.
   679         '''Perform expansion. t is name of map element to expand.
   672         mapping contains added elements for use during expansion. Is a
   680         mapping contains added elements for use during expansion. Is a
   673         generator.'''
   681         generator.'''
   674         func, data = self._load(t)
   682         func, data = self._load(t)
       
   683         return self._expand(func, data, mapping)
       
   684 
       
   685     def expand(self, tmpl, mapping):
       
   686         """Perform expansion over a literal template
       
   687 
       
   688         No user aliases will be expanded since this is supposed to be called
       
   689         with an internal template string.
       
   690         """
       
   691         func, data = self._parse(tmpl)
       
   692         return self._expand(func, data, mapping)
       
   693 
       
   694     def _expand(self, func, data, mapping):
   675         # populate additional items only if they don't exist in the given
   695         # populate additional items only if they don't exist in the given
   676         # mapping. this is slightly different from overlaymap() because the
   696         # mapping. this is slightly different from overlaymap() because the
   677         # initial 'revcache' may contain pre-computed items.
   697         # initial 'revcache' may contain pre-computed items.
   678         extramapping = self._resources.populatemap(self, {}, mapping)
   698         extramapping = self._resources.populatemap(self, {}, mapping)
   679         if extramapping:
   699         if extramapping: