comparison mercurial/match.py @ 32500:369c2d5eeea3

match: remove support for exact matching from main matcher class Exact matching is now handled by the exactmatcher class. We can safely remove _files from the __repr__() implementation, because even though the field is set, the patternspat field is enough for the representation to be unambiguous (which was not the case when the matcher could handle exact matches).
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 18 May 2017 23:39:39 -0700
parents a3583852861a
children 7095dbc266e3
comparison
equal deleted inserted replaced
32499:a3583852861a 32500:369c2d5eeea3
144 144
145 if exact: 145 if exact:
146 m = exactmatcher(root, cwd, patterns, badfn) 146 m = exactmatcher(root, cwd, patterns, badfn)
147 else: 147 else:
148 m = matcher(root, cwd, normalize, patterns, include=None, 148 m = matcher(root, cwd, normalize, patterns, include=None,
149 default=default, exact=exact, auditor=auditor, ctx=ctx, 149 default=default, auditor=auditor, ctx=ctx,
150 listsubrepos=listsubrepos, warn=warn, badfn=badfn) 150 listsubrepos=listsubrepos, warn=warn, badfn=badfn)
151 if include: 151 if include:
152 im = matcher(root, cwd, normalize, [], include=include, default=default, 152 im = matcher(root, cwd, normalize, [], include=include, default=default,
153 exact=False, auditor=auditor, ctx=ctx, 153 auditor=auditor, ctx=ctx, listsubrepos=listsubrepos,
154 listsubrepos=listsubrepos, warn=warn, badfn=None) 154 warn=warn, badfn=None)
155 m = intersectmatchers(m, im) 155 m = intersectmatchers(m, im)
156 if exclude: 156 if exclude:
157 em = matcher(root, cwd, normalize, [], include=exclude, default=default, 157 em = matcher(root, cwd, normalize, [], include=exclude, default=default,
158 exact=False, auditor=auditor, ctx=ctx, 158 auditor=auditor, ctx=ctx, listsubrepos=listsubrepos,
159 listsubrepos=listsubrepos, warn=warn, badfn=None) 159 warn=warn, badfn=None)
160 m = differencematcher(m, em) 160 m = differencematcher(m, em)
161 return m 161 return m
162 162
163 def exact(root, cwd, files, badfn=None): 163 def exact(root, cwd, files, badfn=None):
164 return exactmatcher(root, cwd, files, badfn=badfn) 164 return exactmatcher(root, cwd, files, badfn=badfn)
312 return not self.always() and not self.isexact() and not self.anypats() 312 return not self.always() and not self.isexact() and not self.anypats()
313 313
314 class matcher(basematcher): 314 class matcher(basematcher):
315 315
316 def __init__(self, root, cwd, normalize, patterns, include=None, 316 def __init__(self, root, cwd, normalize, patterns, include=None,
317 default='glob', exact=False, auditor=None, ctx=None, 317 default='glob', auditor=None, ctx=None,
318 listsubrepos=False, warn=None, badfn=None): 318 listsubrepos=False, warn=None, badfn=None):
319 super(matcher, self).__init__(root, cwd, badfn, 319 super(matcher, self).__init__(root, cwd, badfn,
320 relativeuipath=bool(include or patterns)) 320 relativeuipath=bool(include or patterns))
321 if include is None: 321 if include is None:
322 include = [] 322 include = []
340 self._anyincludepats = _anypats(kindpats) 340 self._anyincludepats = _anypats(kindpats)
341 roots, dirs = _rootsanddirs(kindpats) 341 roots, dirs = _rootsanddirs(kindpats)
342 self._includeroots.update(roots) 342 self._includeroots.update(roots)
343 self._includedirs.update(dirs) 343 self._includedirs.update(dirs)
344 matchfns.append(im) 344 matchfns.append(im)
345 if exact: 345 if patterns:
346 if isinstance(patterns, list):
347 self._files = patterns
348 else:
349 self._files = list(patterns)
350 matchfns.append(self.exact)
351 elif patterns:
352 kindpats = normalize(patterns, default, root, cwd, auditor, warn) 346 kindpats = normalize(patterns, default, root, cwd, auditor, warn)
353 if not _kindpatsalwaysmatch(kindpats): 347 if not _kindpatsalwaysmatch(kindpats):
354 self._files = _explicitfiles(kindpats) 348 self._files = _explicitfiles(kindpats)
355 self._anypats = self._anypats or _anypats(kindpats) 349 self._anypats = self._anypats or _anypats(kindpats)
356 self.patternspat, pm = _buildmatch(ctx, kindpats, '$', 350 self.patternspat, pm = _buildmatch(ctx, kindpats, '$',
400 return self._anypats 394 return self._anypats
401 395
402 def always(self): 396 def always(self):
403 return self._always 397 return self._always
404 398
405 def isexact(self):
406 return self.matchfn == self.exact
407
408 def __repr__(self): 399 def __repr__(self):
409 return ('<matcher files=%r, patterns=%r, includes=%r>' % 400 return ('<matcher patterns=%r, includes=%r>' %
410 (self._files, self.patternspat, self.includepat)) 401 (self.patternspat, self.includepat))
411 402
412 class exactmatcher(basematcher): 403 class exactmatcher(basematcher):
413 '''Matches the input files exactly. They are interpreted as paths, not 404 '''Matches the input files exactly. They are interpreted as paths, not
414 patterns (so no kind-prefixes). 405 patterns (so no kind-prefixes).
415 ''' 406 '''