Mercurial > hg
comparison mercurial/match.py @ 32396:ec0311a3a4da
match: pass 'warn' argument to _normalize() for consistency
No other arguments are passed via the matcher's state, so we should
treat 'warn' the consistently. More importantly, this will let us make
it a static function, which will help with further refactoring.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 18 May 2017 15:11:04 -0700 |
parents | 24245b54aa8a |
children | 0ec4cd6fe051 |
comparison
equal
deleted
inserted
replaced
32395:24245b54aa8a | 32396:ec0311a3a4da |
---|---|
158 self._cwd = cwd | 158 self._cwd = cwd |
159 self._files = [] # exact files and roots of patterns | 159 self._files = [] # exact files and roots of patterns |
160 self._anypats = bool(include or exclude) | 160 self._anypats = bool(include or exclude) |
161 self._always = False | 161 self._always = False |
162 self._pathrestricted = bool(include or exclude or patterns) | 162 self._pathrestricted = bool(include or exclude or patterns) |
163 self._warn = warn | |
164 | 163 |
165 # roots are directories which are recursively included/excluded. | 164 # roots are directories which are recursively included/excluded. |
166 self._includeroots = set() | 165 self._includeroots = set() |
167 self._excluderoots = set() | 166 self._excluderoots = set() |
168 # dirs are directories which are non-recursively included. | 167 # dirs are directories which are non-recursively included. |
171 if badfn is not None: | 170 if badfn is not None: |
172 self.bad = badfn | 171 self.bad = badfn |
173 | 172 |
174 matchfns = [] | 173 matchfns = [] |
175 if include: | 174 if include: |
176 kindpats = self._normalize(include, 'glob', root, cwd, auditor) | 175 kindpats = self._normalize(include, 'glob', root, cwd, auditor, |
176 warn) | |
177 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)', | 177 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)', |
178 listsubrepos, root) | 178 listsubrepos, root) |
179 roots, dirs = _rootsanddirs(kindpats) | 179 roots, dirs = _rootsanddirs(kindpats) |
180 self._includeroots.update(roots) | 180 self._includeroots.update(roots) |
181 self._includedirs.update(dirs) | 181 self._includedirs.update(dirs) |
182 matchfns.append(im) | 182 matchfns.append(im) |
183 if exclude: | 183 if exclude: |
184 kindpats = self._normalize(exclude, 'glob', root, cwd, auditor) | 184 kindpats = self._normalize(exclude, 'glob', root, cwd, auditor, |
185 warn) | |
185 self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)', | 186 self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)', |
186 listsubrepos, root) | 187 listsubrepos, root) |
187 if not _anypats(kindpats): | 188 if not _anypats(kindpats): |
188 # Only consider recursive excludes as such - if a non-recursive | 189 # Only consider recursive excludes as such - if a non-recursive |
189 # exclude is used, we must still recurse into the excluded | 190 # exclude is used, we must still recurse into the excluded |
197 self._files = patterns | 198 self._files = patterns |
198 else: | 199 else: |
199 self._files = list(patterns) | 200 self._files = list(patterns) |
200 matchfns.append(self.exact) | 201 matchfns.append(self.exact) |
201 elif patterns: | 202 elif patterns: |
202 kindpats = self._normalize(patterns, default, root, cwd, auditor) | 203 kindpats = self._normalize(patterns, default, root, cwd, auditor, |
204 warn) | |
203 if not _kindpatsalwaysmatch(kindpats): | 205 if not _kindpatsalwaysmatch(kindpats): |
204 self._files = _explicitfiles(kindpats) | 206 self._files = _explicitfiles(kindpats) |
205 self._anypats = self._anypats or _anypats(kindpats) | 207 self._anypats = self._anypats or _anypats(kindpats) |
206 self.patternspat, pm = _buildmatch(ctx, kindpats, '$', | 208 self.patternspat, pm = _buildmatch(ctx, kindpats, '$', |
207 listsubrepos, root) | 209 listsubrepos, root) |
320 return self.matchfn == self.exact | 322 return self.matchfn == self.exact |
321 | 323 |
322 def prefix(self): | 324 def prefix(self): |
323 return not self.always() and not self.isexact() and not self.anypats() | 325 return not self.always() and not self.isexact() and not self.anypats() |
324 | 326 |
325 def _normalize(self, patterns, default, root, cwd, auditor): | 327 def _normalize(self, patterns, default, root, cwd, auditor, warn): |
326 '''Convert 'kind:pat' from the patterns list to tuples with kind and | 328 '''Convert 'kind:pat' from the patterns list to tuples with kind and |
327 normalized and rooted patterns and with listfiles expanded.''' | 329 normalized and rooted patterns and with listfiles expanded.''' |
328 kindpats = [] | 330 kindpats = [] |
329 for kind, pat in [_patsplit(p, default) for p in patterns]: | 331 for kind, pat in [_patsplit(p, default) for p in patterns]: |
330 if kind in ('glob', 'relpath'): | 332 if kind in ('glob', 'relpath'): |
340 files = files.splitlines() | 342 files = files.splitlines() |
341 files = [f for f in files if f] | 343 files = [f for f in files if f] |
342 except EnvironmentError: | 344 except EnvironmentError: |
343 raise error.Abort(_("unable to read file list (%s)") % pat) | 345 raise error.Abort(_("unable to read file list (%s)") % pat) |
344 for k, p, source in self._normalize(files, default, root, cwd, | 346 for k, p, source in self._normalize(files, default, root, cwd, |
345 auditor): | 347 auditor, warn): |
346 kindpats.append((k, p, pat)) | 348 kindpats.append((k, p, pat)) |
347 continue | 349 continue |
348 elif kind == 'include': | 350 elif kind == 'include': |
349 try: | 351 try: |
350 fullpath = os.path.join(root, util.localpath(pat)) | 352 fullpath = os.path.join(root, util.localpath(pat)) |
351 includepats = readpatternfile(fullpath, self._warn) | 353 includepats = readpatternfile(fullpath, warn) |
352 for k, p, source in self._normalize(includepats, default, | 354 for k, p, source in self._normalize(includepats, default, |
353 root, cwd, auditor): | 355 root, cwd, auditor, |
356 warn): | |
354 kindpats.append((k, p, source or pat)) | 357 kindpats.append((k, p, source or pat)) |
355 except error.Abort as inst: | 358 except error.Abort as inst: |
356 raise error.Abort('%s: %s' % (pat, inst[0])) | 359 raise error.Abort('%s: %s' % (pat, inst[0])) |
357 except IOError as inst: | 360 except IOError as inst: |
358 if self._warn: | 361 if warn: |
359 self._warn(_("skipping unreadable pattern file " | 362 warn(_("skipping unreadable pattern file '%s': %s\n") % |
360 "'%s': %s\n") % (pat, inst.strerror)) | 363 (pat, inst.strerror)) |
361 continue | 364 continue |
362 # else: re or relre - which cannot be normalized | 365 # else: re or relre - which cannot be normalized |
363 kindpats.append((kind, pat, '')) | 366 kindpats.append((kind, pat, '')) |
364 return kindpats | 367 return kindpats |
365 | 368 |
450 if self._files: | 453 if self._files: |
451 roots, dirs = _rootsanddirs(self._kp) | 454 roots, dirs = _rootsanddirs(self._kp) |
452 self._fileset = set(roots) | 455 self._fileset = set(roots) |
453 self._fileset.update(dirs) | 456 self._fileset.update(dirs) |
454 | 457 |
455 def _normalize(self, patterns, default, root, cwd, auditor): | 458 def _normalize(self, patterns, default, root, cwd, auditor, warn): |
456 self._kp = super(icasefsmatcher, self)._normalize(patterns, default, | 459 self._kp = super(icasefsmatcher, self)._normalize(patterns, default, |
457 root, cwd, auditor) | 460 root, cwd, auditor, |
461 warn) | |
458 kindpats = [] | 462 kindpats = [] |
459 for kind, pats, source in self._kp: | 463 for kind, pats, source in self._kp: |
460 if kind not in ('re', 'relre'): # regex can't be normalized | 464 if kind not in ('re', 'relre'): # regex can't be normalized |
461 p = pats | 465 p = pats |
462 pats = self._dsnormalize(pats) | 466 pats = self._dsnormalize(pats) |