Patchwork [2,of,3] templater: introduce unified filter syntax for unary functions

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 25, 2015, 2:13 p.m.
Message ID <072f8e2e919778a783a8.1440511980@mimosa>
Download mbox | patch
Permalink /patch/10271/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 25, 2015, 2:13 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1435993416 -32400
#      Sat Jul 04 16:03:36 2015 +0900
# Node ID 072f8e2e919778a783a8548fe303910bb485c397
# Parent  d78be71877dfacd9e1980b7c9ceb6bfd5b859417
templater: introduce unified filter syntax for unary functions

"filter(expr)" is allowed already. This patch adds the opposite, "expr|func".

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -252,6 +252,9 @@  def buildfilter(exp, context):
     if n in context._filters:
         filt = context._filters[n]
         return (runfilter, (func, data, filt))
+    if n in funcs:
+        f = funcs[n]
+        return (f, [(func, data)])
     raise error.ParseError(_("unknown function '%s'") % n)
 
 def runfilter(context, mapping, data):
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
@@ -3117,6 +3117,8 @@  Test shortest(node) function:
   e777603221
   bcc7ff960b
   f7769ec2ab
+  $ hg log --template '{node|shortest}\n' -l1
+  e777
 
 Test pad function