changeset 19336:666aa90258e6

merge with crew
author Matt Mackall <mpm@selenic.com>
date Sun, 30 Jun 2013 14:56:04 -0500
parents 867b9957d895 (diff) 77440de177f7 (current diff)
children 648d1974b3f3
files
diffstat 3 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/help/templates.txt	Wed Jun 26 23:12:55 2013 +0200
+++ b/mercurial/help/templates.txt	Sun Jun 30 14:56:04 2013 -0500
@@ -62,6 +62,8 @@
 
 - rstdoc(text, style)
 
+- strip(text, chars)
+
 Also, for any expression that returns a list, there is a list operator:
 
 - expr % "{template}"
--- a/mercurial/templater.py	Wed Jun 26 23:12:55 2013 +0200
+++ b/mercurial/templater.py	Sun Jun 30 14:56:04 2013 -0500
@@ -333,6 +333,16 @@
         return util.datestr(date, fmt)
     return util.datestr(date)
 
+def strip(context, mapping, args):
+    if not (1 <= len(args) <= 2):
+        raise error.ParseError(_("strip expects one or two arguments"))
+
+    text = args[0][0](context, mapping, args[0][1])
+    if len(args) == 2:
+        chars = args[1][0](context, mapping, args[1][1])
+        return text.strip(chars)
+    return text.strip()
+
 methods = {
     "string": lambda e, c: (runstring, e[1]),
     "symbol": lambda e, c: (runsymbol, e[1]),
@@ -353,6 +363,7 @@
     "sub": sub,
     "fill": fill,
     "date": date,
+    "strip": strip,
 }
 
 # template engine
--- a/tests/test-command-template.t	Wed Jun 26 23:12:55 2013 +0200
+++ b/tests/test-command-template.t	Sun Jun 30 14:56:04 2013 -0500
@@ -1536,3 +1536,31 @@
 
   $ hg log -R latesttag -r 10 --template '{sub("[0-9]", "x", "{rev}")}\n'
   xx
+
+Test the strip function with chars specified:
+
+  $ hg log -R latesttag --template '{desc}\n'
+  at3
+  t5
+  t3
+  t2
+  t1
+  merge
+  h2e
+  h2d
+  h1c
+  b
+  a
+
+  $ hg log -R latesttag --template '{strip(desc, "te")}\n'
+  at3
+  5
+  3
+  2
+  1
+  merg
+  h2
+  h2d
+  h1c
+  b
+  a