##// END OF EJS Templates
templater: fix ifcontains() to handle type mismatch gracefully...
Yuya Nishihara -
r34660:3edfd472 default
parent child Browse files
Show More
@@ -797,10 +797,14 def ifcontains(context, mapping, args):
797 raise error.ParseError(_("ifcontains expects three or four arguments"))
797 raise error.ParseError(_("ifcontains expects three or four arguments"))
798
798
799 haystack = evalfuncarg(context, mapping, args[1])
799 haystack = evalfuncarg(context, mapping, args[1])
800 try:
800 needle = evalastype(context, mapping, args[0],
801 needle = evalastype(context, mapping, args[0],
801 getattr(haystack, 'keytype', None) or bytes)
802 getattr(haystack, 'keytype', None) or bytes)
803 found = (needle in haystack)
804 except error.ParseError:
805 found = False
802
806
803 if needle in haystack:
807 if found:
804 yield evalrawexp(context, mapping, args[2])
808 yield evalrawexp(context, mapping, args[2])
805 elif len(args) == 4:
809 elif len(args) == 4:
806 yield evalrawexp(context, mapping, args[3])
810 yield evalrawexp(context, mapping, args[3])
@@ -3948,6 +3948,9 Test revset function
3948 1 match rev
3948 1 match rev
3949 0 not match rev
3949 0 not match rev
3950
3950
3951 $ hg log -T '{ifcontains(desc, revset(":"), "", "type not match")}\n' -l1
3952 type not match
3953
3951 $ hg log --template '{rev} Parents: {revset("parents(%s)", rev)}\n'
3954 $ hg log --template '{rev} Parents: {revset("parents(%s)", rev)}\n'
3952 2 Parents: 1
3955 2 Parents: 1
3953 1 Parents: 0
3956 1 Parents: 0
General Comments 0
You need to be logged in to leave comments. Login now