mercurial/templater.py
changeset 21821 4a445dc5abff
parent 21798 f2c617ff2abc
child 21822 028a48105191
--- a/mercurial/templater.py	Thu Jun 12 17:45:41 2014 -0700
+++ b/mercurial/templater.py	Thu Jun 12 17:53:37 2014 -0700
@@ -466,6 +466,17 @@
     src = stringify(_evalifliteral(args[2], context, mapping))
     yield re.sub(pat, rpl, src)
 
+def startswith(context, mapping, args):
+    if len(args) != 2:
+        raise error.ParseError(_("startswith expects two arguments"))
+
+    patn = stringify(args[0][0](context, mapping, args[0][1]))
+    text = stringify(args[1][0](context, mapping, args[1][1]))
+    if text.startswith(patn):
+        return text
+    return ''
+
+
 methods = {
     "string": lambda e, c: (runstring, e[1]),
     "rawstring": lambda e, c: (runrawstring, e[1]),
@@ -490,6 +501,7 @@
     "revset": revset,
     "rstdoc": rstdoc,
     "shortest": shortest,
+    "startswith": startswith,
     "strip": strip,
     "sub": sub,
 }