mercurial/templater.py
changeset 22434 40ce05b50148
parent 22304 5678b0e3608f
child 22633 92b54547ac5d
--- a/mercurial/templater.py	Tue Sep 16 11:08:29 2014 -0500
+++ b/mercurial/templater.py	Thu Aug 28 22:45:36 2014 +0900
@@ -225,6 +225,23 @@
         return util.datestr(date, fmt)
     return util.datestr(date)
 
+def diff(context, mapping, args):
+    if len(args) > 2:
+        # i18n: "diff" is a keyword
+        raise error.ParseError(_("diff expects one, two or no arguments"))
+
+    def getpatterns(i):
+        if i < len(args):
+            s = args[i][1].strip()
+            if s:
+                return [s]
+        return []
+
+    ctx = mapping['ctx']
+    chunks = ctx.diff(match=ctx.match([], getpatterns(0), getpatterns(1)))
+
+    return ''.join(chunks)
+
 def fill(context, mapping, args):
     if not (1 <= len(args) <= 4):
         raise error.ParseError(_("fill expects one to four arguments"))
@@ -516,6 +533,7 @@
 
 funcs = {
     "date": date,
+    "diff": diff,
     "fill": fill,
     "get": get,
     "if": if_,