comparison mercurial/match.py @ 44009:e685fac56693

match: resolve filesets against the passed `cwd`, not the current one This allows filesets to be resolved relative to `repo.root`, the same as other patterns are since f02d3c0eed18. The current example in contrib/ wasn't working from the tests directory because of this. Differential Revision: https://phab.mercurial-scm.org/D7570
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 06 Dec 2019 20:40:02 -0500
parents d9d78e70149a
children 3bd77c64bc74
comparison
equal deleted inserted replaced
44008:ac72e17457e5 44009:e685fac56693
55 return m.test_match 55 return m.test_match
56 except AttributeError: 56 except AttributeError:
57 return m.match 57 return m.match
58 58
59 59
60 def _expandsets(kindpats, ctx=None, listsubrepos=False, badfn=None): 60 def _expandsets(cwd, kindpats, ctx=None, listsubrepos=False, badfn=None):
61 '''Returns the kindpats list with the 'set' patterns expanded to matchers''' 61 '''Returns the kindpats list with the 'set' patterns expanded to matchers'''
62 matchers = [] 62 matchers = []
63 other = [] 63 other = []
64 64
65 for kind, pat, source in kindpats: 65 for kind, pat, source in kindpats:
66 if kind == b'set': 66 if kind == b'set':
67 if ctx is None: 67 if ctx is None:
68 raise error.ProgrammingError( 68 raise error.ProgrammingError(
69 b"fileset expression with no context" 69 b"fileset expression with no context"
70 ) 70 )
71 matchers.append(ctx.matchfileset(pat, badfn=badfn)) 71 matchers.append(ctx.matchfileset(cwd, pat, badfn=badfn))
72 72
73 if listsubrepos: 73 if listsubrepos:
74 for subpath in ctx.substate: 74 for subpath in ctx.substate:
75 sm = ctx.sub(subpath).matchfileset(pat, badfn=badfn) 75 sm = ctx.sub(subpath).matchfileset(cwd, pat, badfn=badfn)
76 pm = prefixdirmatcher(subpath, sm, badfn=badfn) 76 pm = prefixdirmatcher(subpath, sm, badfn=badfn)
77 matchers.append(pm) 77 matchers.append(pm)
78 78
79 continue 79 continue
80 other.append((kind, pat, source)) 80 other.append((kind, pat, source))
115 return False 115 return False
116 return True 116 return True
117 117
118 118
119 def _buildkindpatsmatcher( 119 def _buildkindpatsmatcher(
120 matchercls, root, kindpats, ctx=None, listsubrepos=False, badfn=None 120 matchercls, root, cwd, kindpats, ctx=None, listsubrepos=False, badfn=None,
121 ): 121 ):
122 matchers = [] 122 matchers = []
123 fms, kindpats = _expandsets( 123 fms, kindpats = _expandsets(
124 kindpats, ctx=ctx, listsubrepos=listsubrepos, badfn=badfn 124 cwd, kindpats, ctx=ctx, listsubrepos=listsubrepos, badfn=badfn,
125 ) 125 )
126 if kindpats: 126 if kindpats:
127 m = matchercls(root, kindpats, badfn=badfn) 127 m = matchercls(root, kindpats, badfn=badfn)
128 matchers.append(m) 128 matchers.append(m)
129 if fms: 129 if fms:
259 m = alwaysmatcher(badfn) 259 m = alwaysmatcher(badfn)
260 else: 260 else:
261 m = _buildkindpatsmatcher( 261 m = _buildkindpatsmatcher(
262 patternmatcher, 262 patternmatcher,
263 root, 263 root,
264 cwd,
264 kindpats, 265 kindpats,
265 ctx=ctx, 266 ctx=ctx,
266 listsubrepos=listsubrepos, 267 listsubrepos=listsubrepos,
267 badfn=badfn, 268 badfn=badfn,
268 ) 269 )
274 if include: 275 if include:
275 kindpats = normalize(include, b'glob', root, cwd, auditor, warn) 276 kindpats = normalize(include, b'glob', root, cwd, auditor, warn)
276 im = _buildkindpatsmatcher( 277 im = _buildkindpatsmatcher(
277 includematcher, 278 includematcher,
278 root, 279 root,
280 cwd,
279 kindpats, 281 kindpats,
280 ctx=ctx, 282 ctx=ctx,
281 listsubrepos=listsubrepos, 283 listsubrepos=listsubrepos,
282 badfn=None, 284 badfn=None,
283 ) 285 )
285 if exclude: 287 if exclude:
286 kindpats = normalize(exclude, b'glob', root, cwd, auditor, warn) 288 kindpats = normalize(exclude, b'glob', root, cwd, auditor, warn)
287 em = _buildkindpatsmatcher( 289 em = _buildkindpatsmatcher(
288 includematcher, 290 includematcher,
289 root, 291 root,
292 cwd,
290 kindpats, 293 kindpats,
291 ctx=ctx, 294 ctx=ctx,
292 listsubrepos=listsubrepos, 295 listsubrepos=listsubrepos,
293 badfn=None, 296 badfn=None,
294 ) 297 )