comparison mercurial/templater.py @ 13187:e3b87fb34d00

templater: clarify engine caching
author Matt Mackall <mpm@selenic.com>
date Wed, 22 Dec 2010 13:16:03 -0600
parents 895f54a79c6e
children e798e430c5e5
comparison
equal deleted inserted replaced
13186:fda7ae939344 13187:e3b87fb34d00
280 self.base = (mapfile and os.path.dirname(mapfile)) or '' 280 self.base = (mapfile and os.path.dirname(mapfile)) or ''
281 self.filters = templatefilters.filters.copy() 281 self.filters = templatefilters.filters.copy()
282 self.filters.update(filters) 282 self.filters.update(filters)
283 self.defaults = defaults 283 self.defaults = defaults
284 self.minchunk, self.maxchunk = minchunk, maxchunk 284 self.minchunk, self.maxchunk = minchunk, maxchunk
285 self.engines = {} 285 self.ecache = {}
286 286
287 if not mapfile: 287 if not mapfile:
288 return 288 return
289 if not os.path.exists(mapfile): 289 if not os.path.exists(mapfile):
290 raise util.Abort(_('style not found: %s') % mapfile) 290 raise util.Abort(_('style not found: %s') % mapfile)
320 (self.map[t][1], inst.args[1])) 320 (self.map[t][1], inst.args[1]))
321 return self.cache[t] 321 return self.cache[t]
322 322
323 def __call__(self, t, **mapping): 323 def __call__(self, t, **mapping):
324 ttype = t in self.map and self.map[t][0] or 'default' 324 ttype = t in self.map and self.map[t][0] or 'default'
325 proc = self.engines.get(ttype) 325 if ttype not in self.ecache:
326 if proc is None: 326 self.ecache[ttype] = engines[ttype](self.load,
327 proc = engines[ttype](self.load, self.filters, self.defaults) 327 self.filters, self.defaults)
328 self.engines[ttype] = proc 328 proc = self.ecache[ttype]
329 329
330 stream = proc.process(t, mapping) 330 stream = proc.process(t, mapping)
331 if self.minchunk: 331 if self.minchunk:
332 stream = util.increasingchunks(stream, min=self.minchunk, 332 stream = util.increasingchunks(stream, min=self.minchunk,
333 max=self.maxchunk) 333 max=self.maxchunk)