Patchwork [4,of,7] templater: fix shortest() to evaluate int argument and handle error

login
register
mail settings
Submitter Yuya Nishihara
Date March 4, 2016, 3:48 p.m.
Message ID <6914e9e8b8e547b56bdc.1457106526@mimosa>
Download mbox | patch
Permalink /patch/13600/
State Accepted
Headers show

Comments

Yuya Nishihara - March 4, 2016, 3:48 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1455422957 -32400
#      Sun Feb 14 13:09:17 2016 +0900
# Node ID 6914e9e8b8e547b56bdc4416c89b1b873d6074a9
# Parent  6e04f8b6594ef2ee0cc87d10a06c09f43e10b4c6
templater: fix shortest() to evaluate int argument and handle error

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -621,7 +621,9 @@  def shortest(context, mapping, args):
 
     minlength = 4
     if len(args) > 1:
-        minlength = int(args[1][1])
+        minlength = evalinteger(context, mapping, args[1],
+                                # i18n: "shortest" is a keyword
+                                _("shortest() expects an integer minlength"))
 
     cl = mapping['ctx']._repo.changelog
     def isvalid(test):
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
@@ -3219,6 +3219,12 @@  Test shortest(node) function:
   $ hg log --template '{node|shortest}\n' -l1
   e777
 
+  $ hg log -r 0 -T '{shortest(node, "1{"0"}")}\n'
+  f7769ec2ab
+  $ hg log -r 0 -T '{shortest(node, "not an int")}\n'
+  hg: parse error: shortest() expects an integer minlength
+  [255]
+
 Test pad function
 
   $ hg log --template '{pad(rev, 20)} {author|user}\n'