# HG changeset patch # User Boris Feld # Date 1526994172 -7200 # Node ID 4455e5d4d59c74ba2553cdd59c52f4c314b2b5ab # Parent cf24f678addaef55b00dc99c947808057951d910 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 new other arguments, we upgrade the diff options to its own explicit argument. diff -r cf24f678adda -r 4455e5d4d59c contrib/synthrepo.py --- a/contrib/synthrepo.py Sun Jul 01 01:00:39 2018 +0530 +++ b/contrib/synthrepo.py Tue May 22 15:02:52 2018 +0200 @@ -193,7 +193,8 @@ if lastctx.rev() != nullrev: timedelta = ctx.date()[0] - lastctx.date()[0] interarrival[roundto(timedelta, 300)] += 1 - diff = sum((d.splitlines() for d in ctx.diff(pctx, git=True)), []) + diff = sum((d.splitlines() + for d in ctx.diff(pctx, opts={'git': True})), []) fileadds, diradds, fileremoves, filechanges = 0, 0, 0, 0 for filename, mar, lineadd, lineremove, isbin in parsegitdiff(diff): if isbin: diff -r cf24f678adda -r 4455e5d4d59c mercurial/context.py --- a/mercurial/context.py Sun Jul 01 01:00:39 2018 +0530 +++ b/mercurial/context.py Tue May 22 15:02:52 2018 +0200 @@ -294,13 +294,13 @@ 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() if ctx2 is not None: ctx2 = self._repo[ctx2] - diffopts = patch.diffopts(self._repo.ui, pycompat.byteskwargs(opts)) + diffopts = patch.diffopts(self._repo.ui, opts) return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts) def dirs(self): diff -r cf24f678adda -r 4455e5d4d59c mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py Sun Jul 01 01:00:39 2018 +0530 +++ b/mercurial/hgweb/webutil.py Tue May 22 15:02:52 2018 +0200 @@ -658,7 +658,7 @@ '''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 -r cf24f678adda -r 4455e5d4d59c mercurial/obsutil.py --- a/mercurial/obsutil.py Sun Jul 01 01:00:39 2018 +0530 +++ b/mercurial/obsutil.py Tue May 22 15:02:52 2018 +0200 @@ -396,9 +396,9 @@ # 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) + leftdiff = leftunfi.diff(opts={'git': True}) rightunfi = rightctx._repo.unfiltered()[rightctx.rev()] - rightdiff = rightunfi.diff(git=1) + rightdiff = rightunfi.diff(opts={'git': True}) left, right = (0, 0) while None not in (left, right): diff -r cf24f678adda -r 4455e5d4d59c mercurial/revset.py --- a/mercurial/revset.py Sun Jul 01 01:00:39 2018 +0530 +++ b/mercurial/revset.py Tue May 22 15:02:52 2018 +0200 @@ -1802,7 +1802,7 @@ 'phase': lambda r: repo[r].phase(), 'substate': lambda r: repo[r].substate, 'summary': lambda r: repo[r].description().splitlines()[0], - 'diff': lambda r: list(repo[r].diff(git=True),) + 'diff': lambda r: list(repo[r].diff(opts={'git': True}),) } for info in fields: getfield = _funcs.get(info, None) diff -r cf24f678adda -r 4455e5d4d59c mercurial/templatekw.py --- a/mercurial/templatekw.py Sun Jul 01 01:00:39 2018 +0530 +++ b/mercurial/templatekw.py Tue May 22 15:02:52 2018 +0200 @@ -263,7 +263,8 @@ "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 -r cf24f678adda -r 4455e5d4d59c tests/test-context.py --- a/tests/test-context.py Sun Jul 01 01:00:39 2018 +0530 +++ b/tests/test-context.py Tue May 22 15:02:52 2018 +0200 @@ -77,7 +77,7 @@ # 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()"