Patchwork template: allow unquoted int function arguments

login
register
mail settings
Submitter Brendan Cully
Date April 8, 2013, 6:26 a.m.
Message ID <5e8ca3d6df6c2c92ad6e.1365402381@zanzibar>
Download mbox | patch
Permalink /patch/1259/
State Accepted
Commit 0615b22da148ad50b2a4c7e8b966f5b949716b8b
Headers show

Comments

Brendan Cully - April 8, 2013, 6:26 a.m.
# HG changeset patch
# User Brendan Cully <brendan@kublai.com>
# Date 1365402350 25200
#      Sun Apr 07 23:25:50 2013 -0700
# Node ID 5e8ca3d6df6c2c92ad6e30ebb05ace3c36f59be7
# Parent  565482e2ac6b71125e74adf409939bf54bad274f
template: allow unquoted int function arguments
Brendan Cully - April 8, 2013, 4:45 p.m.
OBOn Monday, 08 April 2013 at 11:39, Kevin Bullock wrote:
> On Apr 8, 2013, at 1:26 AM, Brendan Cully wrote:
> 
> > # HG changeset patch
> > # User Brendan Cully <brendan@kublai.com>
> > # Date 1365402350 25200
> > #      Sun Apr 07 23:25:50 2013 -0700
> > # Node ID 5e8ca3d6df6c2c92ad6e30ebb05ace3c36f59be7
> > # Parent  565482e2ac6b71125e74adf409939bf54bad274f
> > template: allow unquoted int function arguments
> 
> LGTM.

In crew, thanks.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -66,7 +66,10 @@ 
                     break
                 pos += 1
             sym = program[s:pos]
-            yield ('symbol', sym, s)
+            try:
+                yield('string', str(int(sym)), s)
+            except ValueError:
+                yield ('symbol', sym, s)
             pos -= 1
         elif c == '}':
             pos += 1
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
@@ -1360,6 +1360,12 @@ 
   $ hg log -l1 --template '{date|age}\n'
   7 years from now
 
+Filter with int function argument:
+
+  $ hg log --template '{fill(author, 20)}\n' -r 0
+  User Name
+  <user@hostname>
+
 Error on syntax:
 
   $ echo 'x = "f' >> t