# HG changeset patch # User Yuya Nishihara # Date 1507813751 -32400 # Node ID 3edfd472f3cb4580b5591dc16eb27e819a4ad7dc # Parent dbe1f51188641abd84f453be95c323fcc83dec3d templater: fix ifcontains() to handle type mismatch gracefully This was unintentionally changed in ee0d74083a22. Since ifcontains() takes needle of any types, it shouldn't abort depending on the given container type. diff -r dbe1f5118864 -r 3edfd472f3cb mercurial/templater.py --- a/mercurial/templater.py Thu Oct 12 21:56:13 2017 +0900 +++ b/mercurial/templater.py Thu Oct 12 22:09:11 2017 +0900 @@ -797,10 +797,14 @@ 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 -r dbe1f5118864 -r 3edfd472f3cb tests/test-command-template.t --- a/tests/test-command-template.t Thu Oct 12 21:56:13 2017 +0900 +++ b/tests/test-command-template.t Thu Oct 12 22:09:11 2017 +0900 @@ -3948,6 +3948,9 @@ 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