comparison mercurial/patch.py @ 41512:a02c8b605d31

diff: use match.intersectmatchers() Differential Revision: https://phab.mercurial-scm.org/D5789
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 31 Jan 2019 16:32:54 -0800
parents d1d3094b54f9
children a5d8824483ba
comparison
equal deleted inserted replaced
41511:3028b4073be1 41512:a02c8b605d31
30 diffhelper, 30 diffhelper,
31 diffutil, 31 diffutil,
32 encoding, 32 encoding,
33 error, 33 error,
34 mail, 34 mail,
35 match as matchmod,
35 mdiff, 36 mdiff,
36 pathutil, 37 pathutil,
37 pycompat, 38 pycompat,
38 scmutil, 39 scmutil,
39 similar, 40 similar,
2317 getfilectx = lrugetfilectx() 2318 getfilectx = lrugetfilectx()
2318 2319
2319 ctx1 = repo[node1] 2320 ctx1 = repo[node1]
2320 ctx2 = repo[node2] 2321 ctx2 = repo[node2]
2321 2322
2322 relfiltered = False 2323 if relroot:
2323 if relroot != '' and match.always(): 2324 relrootmatch = scmutil.match(ctx2, pats=[relroot], default='path')
2324 # as a special case, create a new matcher with just the relroot 2325 match = matchmod.intersectmatchers(match, relrootmatch)
2325 pats = [relroot]
2326 match = scmutil.match(ctx2, pats, default='path')
2327 relfiltered = True
2328 2326
2329 if not changes: 2327 if not changes:
2330 changes = ctx1.status(ctx2, match=match) 2328 changes = ctx1.status(ctx2, match=match)
2331 modified, added, removed = changes[:3] 2329 modified, added, removed = changes[:3]
2332 2330
2342 if copy is None: 2340 if copy is None:
2343 copy = {} 2341 copy = {}
2344 if opts.git or opts.upgrade: 2342 if opts.git or opts.upgrade:
2345 copy = copies.pathcopies(ctx1, ctx2, match=match) 2343 copy = copies.pathcopies(ctx1, ctx2, match=match)
2346 2344
2347 if relroot is not None: 2345 if relroot:
2348 if not relfiltered:
2349 # XXX this would ideally be done in the matcher, but that is
2350 # generally meant to 'or' patterns, not 'and' them. In this case we
2351 # need to 'and' all the patterns from the matcher with relroot.
2352 def filterrel(l):
2353 return [f for f in l if f.startswith(relroot)]
2354 modified = filterrel(modified)
2355 added = filterrel(added)
2356 removed = filterrel(removed)
2357 # filter out copies where either side isn't inside the relative root 2346 # filter out copies where either side isn't inside the relative root
2358 copy = dict(((dst, src) for (dst, src) in copy.iteritems() 2347 copy = dict(((dst, src) for (dst, src) in copy.iteritems()
2359 if dst.startswith(relroot) 2348 if dst.startswith(relroot)
2360 and src.startswith(relroot))) 2349 and src.startswith(relroot)))
2361 2350