Patchwork [1,of,4] context: explicitly take diffopts in `context.diff` (API)

login
register
mail settings
Submitter Boris Feld
Date May 24, 2018, 8:38 a.m.
Message ID <4e013ebfa2c64f1849cb.1527151134@FB>
Download mbox | patch
Permalink /patch/31829/
State New
Headers show

Comments

Boris Feld - May 24, 2018, 8:38 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1526994172 -7200
#      Tue May 22 15:02:52 2018 +0200
# Node ID 4e013ebfa2c64f1849cb3a4242c47da981b35198
# Parent  37ef6ee87488ac0095f8dedf75284f64d1d54455
# EXP-Topic diff-cleanup
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 4e013ebfa2c6
context: explicitly take diffopts in `context.diff` (API)

To provide a proper replacement for the `patch.diff(…)` function, the
`context.diff(…)` method needs to be able to take more parameters. To
distinguish the diff options from the other arguments new arguments, we
upgrade the diff options to its own explicit argument.
Yuya Nishihara - May 24, 2018, 1:31 p.m.
On Thu, 24 May 2018 10:38:54 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1526994172 -7200
> #      Tue May 22 15:02:52 2018 +0200
> # Node ID 4e013ebfa2c64f1849cb3a4242c47da981b35198
> # Parent  37ef6ee87488ac0095f8dedf75284f64d1d54455
> # EXP-Topic diff-cleanup
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 4e013ebfa2c6
> context: explicitly take diffopts in `context.diff` (API)
> 
> To provide a proper replacement for the `patch.diff(…)` function, the
> `context.diff(…)` method needs to be able to take more parameters. To
> distinguish the diff options from the other arguments new arguments, we
> upgrade the diff options to its own explicit argument.

A couple more ctx.diff() calls found:

contrib/synthrepo.py:199:52:            diff = sum((d.splitlines() for d in ctx.diff(pctx, git=True)), [])
mercurial/revset.py:1797:39:        'diff': lambda r: list(repo[r].diff(git=True),)

> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -294,7 +294,7 @@ class basectx(object):
>                                auditor=r.nofsauditor, ctx=self,
>                                listsubrepos=listsubrepos, badfn=badfn)
>  
> -    def diff(self, ctx2=None, match=None, **opts):
> +    def diff(self, ctx2=None, match=None, opts=None):
>          """Returns a diff generator for the given contexts and matcher"""
>          if ctx2 is None:
>              ctx2 = self.p1()

Needs to remove pycompat.byteskwargs(opts) since it's no longer a kwargs.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -294,7 +294,7 @@  class basectx(object):
                               auditor=r.nofsauditor, ctx=self,
                               listsubrepos=listsubrepos, badfn=badfn)
 
-    def diff(self, ctx2=None, match=None, **opts):
+    def diff(self, ctx2=None, match=None, opts=None):
         """Returns a diff generator for the given contexts and matcher"""
         if ctx2 is None:
             ctx2 = self.p1()
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -642,7 +642,7 @@  def diffstatgen(ctx, basectx):
     '''Generator function that provides the diffstat data.'''
 
     stats = patch.diffstatdata(
-        util.iterlines(ctx.diff(basectx, noprefix=False)))
+        util.iterlines(ctx.diff(basectx, opts={'noprefix': False})))
     maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats)
     while True:
         yield stats, maxname, maxtotal, addtotal, removetotal, binary
diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py
--- a/mercurial/obsutil.py
+++ b/mercurial/obsutil.py
@@ -396,9 +396,9 @@  def _cmpdiff(leftctx, rightctx):
     # Leftctx or right ctx might be filtered, so we need to use the contexts
     # with an unfiltered repository to safely compute the diff
     leftunfi = leftctx._repo.unfiltered()[leftctx.rev()]
-    leftdiff = leftunfi.diff(git=1)
-    rightunfi = rightctx._repo.unfiltered()[rightctx.rev()]
-    rightdiff = rightunfi.diff(git=1)
+    leftdiff = leftunfi.diff(opts={'git': True})
+    rightunfi = leftctx._repo.unfiltered()[rightctx.rev()]
+    rightdiff = rightunfi.diff(opts={'git': True})
 
     left, right = (0, 0)
     while None not in (left, right):
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -261,7 +261,8 @@  def showdiffstat(context, mapping):
     "modified files: +added/-removed lines"
     """
     ctx = context.resource(mapping, 'ctx')
-    stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False)))
+    diff = ctx.diff(opts={'noprefix': False})
+    stats = patch.diffstatdata(util.iterlines(diff))
     maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
     return '%d: +%d/-%d' % (len(stats), adds, removes)
 
diff --git a/tests/test-context.py b/tests/test-context.py
--- a/tests/test-context.py
+++ b/tests/test-context.py
@@ -77,7 +77,7 @@  print(ctxb.status(ctxa))
 
 # test performing a diff on a memctx
 
-for d in ctxb.diff(ctxa, git=True):
+for d in ctxb.diff(ctxa, opts={'git': True}):
     printb(d, end=b'')
 
 # test safeness and correctness of "ctx.status()"