Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
34855:35c6a54ec1ff | 34856:890afefa7296 |
---|---|
2294 buildopts['noprefix'] = get('noprefix', forceplain=False) | 2294 buildopts['noprefix'] = get('noprefix', forceplain=False) |
2295 | 2295 |
2296 return mdiff.diffopts(**pycompat.strkwargs(buildopts)) | 2296 return mdiff.diffopts(**pycompat.strkwargs(buildopts)) |
2297 | 2297 |
2298 def diff(repo, node1=None, node2=None, match=None, changes=None, | 2298 def diff(repo, node1=None, node2=None, match=None, changes=None, |
2299 opts=None, losedatafn=None, prefix='', relroot='', copy=None): | 2299 opts=None, losedatafn=None, prefix='', relroot='', copy=None, |
2300 hunksfilterfn=None): | |
2300 '''yields diff of changes to files between two nodes, or node and | 2301 '''yields diff of changes to files between two nodes, or node and |
2301 working directory. | 2302 working directory. |
2302 | 2303 |
2303 if node1 is None, use first dirstate parent instead. | 2304 if node1 is None, use first dirstate parent instead. |
2304 if node2 is None, compare node1 with working directory. | 2305 if node2 is None, compare node1 with working directory. |
2316 | 2317 |
2317 relroot, if not empty, must be normalized with a trailing /. Any match | 2318 relroot, if not empty, must be normalized with a trailing /. Any match |
2318 patterns that fall outside it will be ignored. | 2319 patterns that fall outside it will be ignored. |
2319 | 2320 |
2320 copy, if not empty, should contain mappings {dst@y: src@x} of copy | 2321 copy, if not empty, should contain mappings {dst@y: src@x} of copy |
2321 information.''' | 2322 information. |
2323 | |
2324 hunksfilterfn, if not None, should be a function taking a filectx and | |
2325 hunks generator that may yield filtered hunks. | |
2326 ''' | |
2322 for fctx1, fctx2, hdr, hunks in diffhunks( | 2327 for fctx1, fctx2, hdr, hunks in diffhunks( |
2323 repo, node1=node1, node2=node2, | 2328 repo, node1=node1, node2=node2, |
2324 match=match, changes=changes, opts=opts, | 2329 match=match, changes=changes, opts=opts, |
2325 losedatafn=losedatafn, prefix=prefix, relroot=relroot, copy=copy, | 2330 losedatafn=losedatafn, prefix=prefix, relroot=relroot, copy=copy, |
2326 ): | 2331 ): |
2332 if hunksfilterfn is not None: | |
2333 hunks = hunksfilterfn(fctx2, hunks) | |
2327 text = ''.join(sum((list(hlines) for hrange, hlines in hunks), [])) | 2334 text = ''.join(sum((list(hlines) for hrange, hlines in hunks), [])) |
2328 if hdr and (text or len(hdr) > 1): | 2335 if hdr and (text or len(hdr) > 1): |
2329 yield '\n'.join(hdr) + '\n' | 2336 yield '\n'.join(hdr) + '\n' |
2330 if text: | 2337 if text: |
2331 yield text | 2338 yield text |