comparison mercurial/patch.py @ 34855:35c6a54ec1ff

diff: also yield file context objects in patch.trydiff() (API) And retrieve them in patch.diffhunks(). We'll use these in forthcoming changesets to filter diff hunks by line range.
author Denis Laxalde <denis.laxalde@logilab.fr>
date Thu, 05 Oct 2017 21:20:08 +0200
parents 60213a2eca81
children 890afefa7296
comparison
equal deleted inserted replaced
34854:39b094e4ae2c 34855:35c6a54ec1ff
2317 relroot, if not empty, must be normalized with a trailing /. Any match 2317 relroot, if not empty, must be normalized with a trailing /. Any match
2318 patterns that fall outside it will be ignored. 2318 patterns that fall outside it will be ignored.
2319 2319
2320 copy, if not empty, should contain mappings {dst@y: src@x} of copy 2320 copy, if not empty, should contain mappings {dst@y: src@x} of copy
2321 information.''' 2321 information.'''
2322 for hdr, hunks in diffhunks(repo, node1=node1, node2=node2, match=match, 2322 for fctx1, fctx2, hdr, hunks in diffhunks(
2323 changes=changes, opts=opts, 2323 repo, node1=node1, node2=node2,
2324 losedatafn=losedatafn, prefix=prefix, 2324 match=match, changes=changes, opts=opts,
2325 relroot=relroot, copy=copy): 2325 losedatafn=losedatafn, prefix=prefix, relroot=relroot, copy=copy,
2326 ):
2326 text = ''.join(sum((list(hlines) for hrange, hlines in hunks), [])) 2327 text = ''.join(sum((list(hlines) for hrange, hlines in hunks), []))
2327 if hdr and (text or len(hdr) > 1): 2328 if hdr and (text or len(hdr) > 1):
2328 yield '\n'.join(hdr) + '\n' 2329 yield '\n'.join(hdr) + '\n'
2329 if text: 2330 if text:
2330 yield text 2331 yield text
2685 2686
2686 uheaders, hunks = mdiff.unidiff(content1, date1, 2687 uheaders, hunks = mdiff.unidiff(content1, date1,
2687 content2, date2, 2688 content2, date2,
2688 path1, path2, opts=opts) 2689 path1, path2, opts=opts)
2689 header.extend(uheaders) 2690 header.extend(uheaders)
2690 yield header, hunks 2691 yield fctx1, fctx2, header, hunks
2691 2692
2692 def diffstatsum(stats): 2693 def diffstatsum(stats):
2693 maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False 2694 maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False
2694 for f, a, r, b in stats: 2695 for f, a, r, b in stats:
2695 maxfile = max(maxfile, encoding.colwidth(f)) 2696 maxfile = max(maxfile, encoding.colwidth(f))