##// END OF EJS Templates
templater: factor out function to create mapping dict for nested evaluation...
Yuya Nishihara -
r37092:2891079f default
parent child Browse files
Show More
@@ -449,8 +449,8 b' def showlatesttagdistance(context, mappi'
449 @templatekeyword('changessincelatesttag', requires={'repo', 'ctx', 'cache'})
449 @templatekeyword('changessincelatesttag', requires={'repo', 'ctx', 'cache'})
450 def showchangessincelatesttag(context, mapping):
450 def showchangessincelatesttag(context, mapping):
451 """Integer. All ancestors not in the latest tag."""
451 """Integer. All ancestors not in the latest tag."""
452 mapping = mapping.copy()
452 tag = getlatesttags(context, mapping)[2][0]
453 mapping['tag'] = getlatesttags(context, mapping)[2][0]
453 mapping = context.overlaymap(mapping, {'tag': tag})
454 return _showchangessincetag(context, mapping)
454 return _showchangessincetag(context, mapping)
455
455
456 def _showchangessincetag(context, mapping):
456 def _showchangessincetag(context, mapping):
@@ -480,8 +480,7 b' def showmanifest(context, mapping):'
480 return
480 return
481 mrev = repo.manifestlog._revlog.rev(mnode)
481 mrev = repo.manifestlog._revlog.rev(mnode)
482 mhex = hex(mnode)
482 mhex = hex(mnode)
483 mapping = mapping.copy()
483 mapping = context.overlaymap(mapping, {'rev': mrev, 'node': mhex})
484 mapping.update({'rev': mrev, 'node': mhex})
485 f = context.process('manifest', mapping)
484 f = context.process('manifest', mapping)
486 # TODO: perhaps 'ctx' should be dropped from mapping because manifest
485 # TODO: perhaps 'ctx' should be dropped from mapping because manifest
487 # rev and node are completely different from changeset's.
486 # rev and node are completely different from changeset's.
@@ -613,6 +613,13 b' class engine(object):'
613 self._aliasmap = _aliasrules.buildmap(aliases)
613 self._aliasmap = _aliasrules.buildmap(aliases)
614 self._cache = {} # key: (func, data)
614 self._cache = {} # key: (func, data)
615
615
616 def overlaymap(self, origmapping, newmapping):
617 """Create combined mapping from the original mapping and partial
618 mapping to override the original"""
619 mapping = origmapping.copy()
620 mapping.update(newmapping)
621 return mapping
622
616 def symbol(self, mapping, key):
623 def symbol(self, mapping, key):
617 """Resolve symbol to value or function; None if nothing found"""
624 """Resolve symbol to value or function; None if nothing found"""
618 v = None
625 v = None
@@ -202,8 +202,8 b' def _showcompatlist(context, mapping, na'
202 startname = 'start_' + plural
202 startname = 'start_' + plural
203 if context.preload(startname):
203 if context.preload(startname):
204 yield context.process(startname, mapping)
204 yield context.process(startname, mapping)
205 vmapping = mapping.copy()
206 def one(v, tag=name):
205 def one(v, tag=name):
206 vmapping = {}
207 try:
207 try:
208 vmapping.update(v)
208 vmapping.update(v)
209 # Python 2 raises ValueError if the type of v is wrong. Python
209 # Python 2 raises ValueError if the type of v is wrong. Python
@@ -216,6 +216,7 b' def _showcompatlist(context, mapping, na'
216 vmapping[a] = b
216 vmapping[a] = b
217 except (TypeError, ValueError):
217 except (TypeError, ValueError):
218 vmapping[name] = v
218 vmapping[name] = v
219 vmapping = context.overlaymap(mapping, vmapping)
219 return context.process(tag, vmapping)
220 return context.process(tag, vmapping)
220 lastname = 'last_' + name
221 lastname = 'last_' + name
221 if context.preload(lastname):
222 if context.preload(lastname):
@@ -399,10 +400,9 b' def runmap(context, mapping, data):'
399 raise error.ParseError(_("%r is not iterable") % d)
400 raise error.ParseError(_("%r is not iterable") % d)
400
401
401 for i, v in enumerate(diter):
402 for i, v in enumerate(diter):
402 lm = mapping.copy()
403 lm['index'] = i
404 if isinstance(v, dict):
403 if isinstance(v, dict):
405 lm.update(v)
404 lm = context.overlaymap(mapping, v)
405 lm['index'] = i
406 lm['originalnode'] = mapping.get('node')
406 lm['originalnode'] = mapping.get('node')
407 yield evalrawexp(context, lm, targ)
407 yield evalrawexp(context, lm, targ)
408 else:
408 else:
@@ -415,8 +415,7 b' def runmember(context, mapping, data):'
415 darg, memb = data
415 darg, memb = data
416 d = evalrawexp(context, mapping, darg)
416 d = evalrawexp(context, mapping, darg)
417 if util.safehasattr(d, 'tomap'):
417 if util.safehasattr(d, 'tomap'):
418 lm = mapping.copy()
418 lm = context.overlaymap(mapping, d.tomap())
419 lm.update(d.tomap())
420 return runsymbol(context, lm, memb)
419 return runsymbol(context, lm, memb)
421 if util.safehasattr(d, 'get'):
420 if util.safehasattr(d, 'get'):
422 return getdictitem(d, memb)
421 return getdictitem(d, memb)
General Comments 0
You need to be logged in to leave comments. Login now