##// END OF EJS Templates
templatefuncs: specialize "no match" value of search() to allow % operation...
Yuya Nishihara -
r40971:4591c979 default
parent child Browse files
Show More
@@ -609,7 +609,7 b' def search(context, mapping, args):'
609
609
610 match = patre.search(src)
610 match = patre.search(src)
611 if not match:
611 if not match:
612 return
612 return templateutil.mappingnone()
613
613
614 lm = {b'0': match.group(0)}
614 lm = {b'0': match.group(0)}
615 lm.update((b'%d' % i, v) for i, v in enumerate(match.groups(), 1))
615 lm.update((b'%d' % i, v) for i, v in enumerate(match.groups(), 1))
@@ -53,6 +53,10 b' mappingdict'
53 represents a single mapping (i.e. a dict), which may have default output
53 represents a single mapping (i.e. a dict), which may have default output
54 format.
54 format.
55
55
56 mappingnone
57 represents None of Optional[mappable], which will be mapped to an empty
58 string by % operation.
59
56 mappedgenerator
60 mappedgenerator
57 a lazily-evaluated list of byte strings, which is e.g. a result of %
61 a lazily-evaluated list of byte strings, which is e.g. a result of %
58 operation.
62 operation.
@@ -495,6 +495,19 b' class mappingdict(mappable, _mappingsequ'
495 def tovalue(self, context, mapping):
495 def tovalue(self, context, mapping):
496 return super(mappingdict, self).tovalue(context, mapping)[0]
496 return super(mappingdict, self).tovalue(context, mapping)[0]
497
497
498 class mappingnone(wrappedvalue):
499 """Wrapper for None, but supports map operation
500
501 This represents None of Optional[mappable]. It's similar to
502 mapplinglist([]), but the underlying value is not [], but None.
503 """
504
505 def __init__(self):
506 super(mappingnone, self).__init__(None)
507
508 def itermaps(self, context):
509 return iter([])
510
498 class mappedgenerator(wrapped):
511 class mappedgenerator(wrapped):
499 """Wrapper for generator of strings which acts as a list
512 """Wrapper for generator of strings which acts as a list
500
513
@@ -635,11 +635,9 b' Test search() function:'
635 no
635 no
636
636
637 group reference with no match
637 group reference with no match
638 (TODO: we'll probably want to map it to an empty value)
639
638
640 $ hg log -R a -r2 -T '{search(r"q", desc) % "match: {0}"}\n'
639 $ hg log -R a -r2 -T '{search(r"q", desc) % "match: {0}"}\n'
641 hg: parse error: None is not iterable of mappings
640
642 [255]
643
641
644 bad group names
642 bad group names
645
643
General Comments 0
You need to be logged in to leave comments. Login now