Mercurial > public > mercurial-scm > hg-stable
diff mercurial/patch.py @ 34856:890afefa7296
diff: pass a diff hunks filter function from changeset_printer to patch.diff()
We add a 'hunksfilterfn' keyword argument in all functions of the call
stack from changeset_printer.show() to patch.diff(). This is a callable
that will be used to filter out hunks by line range and will be used in
the "-L/--line-range" option of "hg log" command introduced in the
following changesets.
author | Denis Laxalde <denis.laxalde@logilab.fr> |
---|---|
date | Fri, 06 Oct 2017 14:45:17 +0200 |
parents | 35c6a54ec1ff |
children | 907ff34e1460 |
line wrap: on
line diff
--- a/mercurial/patch.py Thu Oct 05 21:20:08 2017 +0200 +++ b/mercurial/patch.py Fri Oct 06 14:45:17 2017 +0200 @@ -2296,7 +2296,8 @@ return mdiff.diffopts(**pycompat.strkwargs(buildopts)) def diff(repo, node1=None, node2=None, match=None, changes=None, - opts=None, losedatafn=None, prefix='', relroot='', copy=None): + opts=None, losedatafn=None, prefix='', relroot='', copy=None, + hunksfilterfn=None): '''yields diff of changes to files between two nodes, or node and working directory. @@ -2318,12 +2319,18 @@ patterns that fall outside it will be ignored. copy, if not empty, should contain mappings {dst@y: src@x} of copy - information.''' + information. + + hunksfilterfn, if not None, should be a function taking a filectx and + hunks generator that may yield filtered hunks. + ''' for fctx1, fctx2, hdr, hunks in diffhunks( repo, node1=node1, node2=node2, match=match, changes=changes, opts=opts, losedatafn=losedatafn, prefix=prefix, relroot=relroot, copy=copy, ): + if hunksfilterfn is not None: + hunks = hunksfilterfn(fctx2, hunks) text = ''.join(sum((list(hlines) for hrange, hlines in hunks), [])) if hdr and (text or len(hdr) > 1): yield '\n'.join(hdr) + '\n'