comparison mercurial/match.py @ 32499:a3583852861a

match: handle exact matching using new exactmatcher
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 17 May 2017 09:26:15 -0700
parents 9eccd559c592
children 369c2d5eeea3
comparison
equal deleted inserted replaced
32498:bd56bea5ecf8 32499:a3583852861a
140 kindpats.append((kind, p, source)) 140 kindpats.append((kind, p, source))
141 141
142 kindpats.append((kind, pats, source)) 142 kindpats.append((kind, pats, source))
143 return kindpats 143 return kindpats
144 144
145 m = matcher(root, cwd, normalize, patterns, include=None, 145 if exact:
146 default=default, exact=exact, auditor=auditor, ctx=ctx, 146 m = exactmatcher(root, cwd, patterns, badfn)
147 listsubrepos=listsubrepos, warn=warn, badfn=badfn) 147 else:
148 m = matcher(root, cwd, normalize, patterns, include=None,
149 default=default, exact=exact, auditor=auditor, ctx=ctx,
150 listsubrepos=listsubrepos, warn=warn, badfn=badfn)
148 if include: 151 if include:
149 im = matcher(root, cwd, normalize, [], include=include, default=default, 152 im = matcher(root, cwd, normalize, [], include=include, default=default,
150 exact=False, auditor=auditor, ctx=ctx, 153 exact=False, auditor=auditor, ctx=ctx,
151 listsubrepos=listsubrepos, warn=warn, badfn=None) 154 listsubrepos=listsubrepos, warn=warn, badfn=None)
152 m = intersectmatchers(m, im) 155 m = intersectmatchers(m, im)
156 listsubrepos=listsubrepos, warn=warn, badfn=None) 159 listsubrepos=listsubrepos, warn=warn, badfn=None)
157 m = differencematcher(m, em) 160 m = differencematcher(m, em)
158 return m 161 return m
159 162
160 def exact(root, cwd, files, badfn=None): 163 def exact(root, cwd, files, badfn=None):
161 return match(root, cwd, files, exact=True, badfn=badfn) 164 return exactmatcher(root, cwd, files, badfn=badfn)
162 165
163 def always(root, cwd): 166 def always(root, cwd):
164 return match(root, cwd, []) 167 return match(root, cwd, [])
165 168
166 def badmatch(match, badfn): 169 def badmatch(match, badfn):
403 return self.matchfn == self.exact 406 return self.matchfn == self.exact
404 407
405 def __repr__(self): 408 def __repr__(self):
406 return ('<matcher files=%r, patterns=%r, includes=%r>' % 409 return ('<matcher files=%r, patterns=%r, includes=%r>' %
407 (self._files, self.patternspat, self.includepat)) 410 (self._files, self.patternspat, self.includepat))
411
412 class exactmatcher(basematcher):
413 '''Matches the input files exactly. They are interpreted as paths, not
414 patterns (so no kind-prefixes).
415 '''
416
417 def __init__(self, root, cwd, files, badfn=None):
418 super(exactmatcher, self).__init__(root, cwd, badfn)
419
420 if isinstance(files, list):
421 self._files = files
422 else:
423 self._files = list(files)
424 self.matchfn = self.exact
425
426 @propertycache
427 def _dirs(self):
428 return set(util.dirs(self._fileset)) | {'.'}
429
430 def visitdir(self, dir):
431 return dir in self._dirs
432
433 def isexact(self):
434 return True
435
436 def __repr__(self):
437 return ('<exactmatcher files=%r>' % self._files)
408 438
409 class differencematcher(basematcher): 439 class differencematcher(basematcher):
410 '''Composes two matchers by matching if the first matches and the second 440 '''Composes two matchers by matching if the first matches and the second
411 does not. Well, almost... If the user provides a pattern like "-X foo foo", 441 does not. Well, almost... If the user provides a pattern like "-X foo foo",
412 Mercurial actually does match "foo" against that. That's because exact 442 Mercurial actually does match "foo" against that. That's because exact