comparison mercurial/templatefuncs.py @ 37272:7d3bc1d4e871

templater: pass (context, mapping) down to unwraphybrid() See the subsequent patches for why. I initially thought it would be wrong to pass a mapping to flatten() and stringify() since these functions may be applied to a tree of generators, where each node should be bound to the mapping when it was evaluated. But, actually that isn't a problem. If an intermediate node has to override a mapping dict, it can do on unwraphybrid() and yield "unwrapped" generator of byte strings: "{f(g(v))}" # literal template example. ^^^^ # g() want to override a mapping, so it returns a wrapped # object 'G{V}' with partial mapping 'lm' attached. ^^^^^^^ # f() stringifies 'G{V}', starting from a mapping 'm'. # when unwrapping 'G{}', it updates 'm' with 'lm', and # passes it to 'V'. This structure is important for the formatter (and the hgweb) to build a static template keyword, which can't access a mapping dict until evaluation phase.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Mar 2018 20:09:05 +0900
parents 8e57c3b0dce4
children 9e8128e84326
comparison
equal deleted inserted replaced
37271:0194dac77c93 37272:7d3bc1d4e871
281 281
282 haystack = evalfuncarg(context, mapping, args[1]) 282 haystack = evalfuncarg(context, mapping, args[1])
283 keytype = getattr(haystack, 'keytype', None) 283 keytype = getattr(haystack, 'keytype', None)
284 try: 284 try:
285 needle = evalrawexp(context, mapping, args[0]) 285 needle = evalrawexp(context, mapping, args[0])
286 needle = templateutil.unwrapastype(needle, keytype or bytes) 286 needle = templateutil.unwrapastype(context, mapping, needle,
287 keytype or bytes)
287 found = (needle in haystack) 288 found = (needle in haystack)
288 except error.ParseError: 289 except error.ParseError:
289 found = False 290 found = False
290 291
291 if found: 292 if found: