Mercurial > hg-stable
changeset 38523:4455e5d4d59c
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.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Tue, 22 May 2018 15:02:52 +0200 |
parents | cf24f678adda |
children | 02633fe3883a |
files | contrib/synthrepo.py mercurial/context.py mercurial/hgweb/webutil.py mercurial/obsutil.py mercurial/revset.py mercurial/templatekw.py tests/test-context.py |
diffstat | 7 files changed, 11 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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:
--- 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):
--- 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
--- 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):
--- 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)
--- 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)
--- 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()"