Patchwork templatefuncs: account for user's diffopts in diff()

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 5, 2019, 10:58 a.m.
Message ID <819f8fffbdf90119836d.1570273104@marimba>
Download mbox | patch
Permalink /patch/41965/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 5, 2019, 10:58 a.m.
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1570269799 -7200
#      Sat Oct 05 12:03:19 2019 +0200
# Node ID 819f8fffbdf90119836d867937302def34c71a8a
# Parent  e370f9e4bfad03977309feb121906d6768907701
templatefuncs: account for user's diffopts in diff()
Yuya Nishihara - Oct. 5, 2019, 3:27 p.m.
On Sat, 05 Oct 2019 12:58:24 +0200, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis@laxalde.org>
> # Date 1570269799 -7200
> #      Sat Oct 05 12:03:19 2019 +0200
> # Node ID 819f8fffbdf90119836d867937302def34c71a8a
> # Parent  e370f9e4bfad03977309feb121906d6768907701
> templatefuncs: account for user's diffopts in diff()

Queued with (BC) flag, thanks.

Patch

diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
index a22c520..3cf8c49 100644
--- a/mercurial/templatefuncs.py
+++ b/mercurial/templatefuncs.py
@@ -16,6 +16,7 @@  from .node import (
 )
 from . import (
     color,
+    diffutil,
     encoding,
     error,
     minirst,
@@ -86,7 +87,8 @@  def dict_(context, mapping, args):
                 for k, v in args['kwargs'].iteritems())
     return templateutil.hybriddict(data)
 
-@templatefunc('diff([includepattern [, excludepattern]])', requires={'ctx'})
+@templatefunc('diff([includepattern [, excludepattern]])',
+              requires={'ctx', 'ui'})
 def diff(context, mapping, args):
     """Show a diff, optionally
     specifying files to include or exclude."""
@@ -102,7 +104,10 @@  def diff(context, mapping, args):
         return []
 
     ctx = context.resource(mapping, 'ctx')
-    chunks = ctx.diff(match=ctx.match([], getpatterns(0), getpatterns(1)))
+    ui = context.resource(mapping, 'ui')
+    diffopts = diffutil.diffallopts(ui)
+    chunks = ctx.diff(match=ctx.match([], getpatterns(0), getpatterns(1)),
+                      opts=diffopts)
 
     return ''.join(chunks)
 
diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t
index a1c4411..c4ccb94 100644
--- a/tests/test-template-functions.t
+++ b/tests/test-template-functions.t
@@ -370,6 +370,17 @@  Test diff function:
   @@ -0,0 +1,1 @@
   +second
 
+  $ hg --config diff.git=true log -r 8 -T "{diff()}"
+  diff --git a/second b/fourth
+  rename from second
+  rename to fourth
+  diff --git a/third b/third
+  new file mode 100644
+  --- /dev/null
+  +++ b/third
+  @@ -0,0 +1,1 @@
+  +third
+
   $ cd ..
 
 latesttag() function: