# HG changeset patch # User Yuya Nishihara # Date 1455421694 -32400 # Node ID ac371d4c007f4252fa5402c436acf14ec584073a # Parent a6c2310b3827d980d29b6c6ac27f65e88603f071 templater: drop redundant type conversion when evaluating integer argument A function argument may be an integer. In this case, it isn't necessary to convert a value to string and back to integer. Because an argument may be an arbitrary object (e.g. date tuple), TypeError should be caught as well. diff -r a6c2310b3827 -r ac371d4c007f mercurial/templater.py --- a/mercurial/templater.py Sun Feb 14 12:42:25 2016 +0900 +++ b/mercurial/templater.py Sun Feb 14 12:48:14 2016 +0900 @@ -221,9 +221,10 @@ return thing def evalinteger(context, mapping, arg, err): + v = evalfuncarg(context, mapping, arg) try: - return int(stringify(arg[0](context, mapping, arg[1]))) - except ValueError: + return int(v) + except (TypeError, ValueError): raise error.ParseError(err) def runinteger(context, mapping, data): diff -r a6c2310b3827 -r ac371d4c007f tests/test-command-template.t --- a/tests/test-command-template.t Sun Feb 14 12:42:25 2016 +0900 +++ b/tests/test-command-template.t Sun Feb 14 12:48:14 2016 +0900 @@ -3148,6 +3148,9 @@ text.1:be wrapped text.1:desc to be text.1:wrapped (no-eol) + $ hg log -l1 -T '{fill(desc, date, "", "")}\n' + hg: parse error: fill expects an integer width + [255] $ hg log -l 1 --template '{sub(r"[0-9]", "-", author)}' {node|short} (no-eol)