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 |