diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -797,10 +797,14 @@ def ifcontains(context, mapping, args): raise error.ParseError(_("ifcontains expects three or four arguments")) haystack = evalfuncarg(context, mapping, args[1]) - needle = evalastype(context, mapping, args[0], - getattr(haystack, 'keytype', None) or bytes) + try: + needle = evalastype(context, mapping, args[0], + getattr(haystack, 'keytype', None) or bytes) + found = (needle in haystack) + except error.ParseError: + found = False - if needle in haystack: + if found: yield evalrawexp(context, mapping, args[2]) elif len(args) == 4: yield evalrawexp(context, mapping, args[3]) diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -3948,6 +3948,9 @@ Test revset function 1 match rev 0 not match rev + $ hg log -T '{ifcontains(desc, revset(":"), "", "type not match")}\n' -l1 + type not match + $ hg log --template '{rev} Parents: {revset("parents(%s)", rev)}\n' 2 Parents: 1 1 Parents: 0