##// END OF EJS Templates
match: add source to kindpats list...
Durham Goode -
r25213:08a8e9da default
parent child Browse files
Show More
@@ -26,7 +26,7 b' def _expandsets(kindpats, ctx, listsubre'
26 26 fset = set()
27 27 other = []
28 28
29 for kind, pat in kindpats:
29 for kind, pat, source in kindpats:
30 30 if kind == 'set':
31 31 if not ctx:
32 32 raise util.Abort("fileset expression with no context")
@@ -39,14 +39,14 b' def _expandsets(kindpats, ctx, listsubre'
39 39 fset.update(subpath + '/' + f for f in s)
40 40
41 41 continue
42 other.append((kind, pat))
42 other.append((kind, pat, source))
43 43 return fset, other
44 44
45 45 def _kindpatsalwaysmatch(kindpats):
46 46 """"Checks whether the kindspats match everything, as e.g.
47 47 'relpath:.' does.
48 48 """
49 for kind, pat in kindpats:
49 for kind, pat, source in kindpats:
50 50 if pat != '' or kind not in ['relpath', 'glob']:
51 51 return False
52 52 return True
@@ -222,10 +222,12 b' class match(object):'
222 222 files = [f for f in files if f]
223 223 except EnvironmentError:
224 224 raise util.Abort(_("unable to read file list (%s)") % pat)
225 kindpats += self._normalize(files, default, root, cwd, auditor)
225 for k, p, source in self._normalize(files, default, root, cwd,
226 auditor):
227 kindpats.append((k, p, pat))
226 228 continue
227 229 # else: re or relre - which cannot be normalized
228 kindpats.append((kind, pat))
230 kindpats.append((kind, pat, ''))
229 231 return kindpats
230 232
231 233 def exact(root, cwd, files):
@@ -315,10 +317,10 b' class icasefsmatcher(match):'
315 317 self._kp = super(icasefsmatcher, self)._normalize(patterns, default,
316 318 root, cwd, auditor)
317 319 kindpats = []
318 for kind, pats in self._kp:
320 for kind, pats, source in self._kp:
319 321 if kind not in ('re', 'relre'): # regex can't be normalized
320 322 pats = self._dsnormalize(pats)
321 kindpats.append((kind, pats))
323 kindpats.append((kind, pats, source))
322 324 return kindpats
323 325
324 326 def patkind(pattern, default=None):
@@ -449,7 +451,7 b' def _buildregexmatch(kindpats, globsuffi'
449 451 return regexp string and a matcher function."""
450 452 try:
451 453 regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix)
452 for (k, p) in kindpats])
454 for (k, p, s) in kindpats])
453 455 if len(regex) > 20000:
454 456 raise OverflowError
455 457 return regex, _rematcher(regex)
@@ -464,25 +466,29 b' def _buildregexmatch(kindpats, globsuffi'
464 466 regexb, b = _buildregexmatch(kindpats[l//2:], globsuffix)
465 467 return regex, lambda s: a(s) or b(s)
466 468 except re.error:
467 for k, p in kindpats:
469 for k, p, s in kindpats:
468 470 try:
469 471 _rematcher('(?:%s)' % _regex(k, p, globsuffix))
470 472 except re.error:
471 raise util.Abort(_("invalid pattern (%s): %s") % (k, p))
473 if s:
474 raise util.Abort(_("%s: invalid pattern (%s): %s") %
475 (s, k, p))
476 else:
477 raise util.Abort(_("invalid pattern (%s): %s") % (k, p))
472 478 raise util.Abort(_("invalid pattern"))
473 479
474 480 def _roots(kindpats):
475 481 '''return roots and exact explicitly listed files from patterns
476 482
477 >>> _roots([('glob', 'g/*'), ('glob', 'g'), ('glob', 'g*')])
483 >>> _roots([('glob', 'g/*', ''), ('glob', 'g', ''), ('glob', 'g*', '')])
478 484 ['g', 'g', '.']
479 >>> _roots([('relpath', 'r'), ('path', 'p/p'), ('path', '')])
485 >>> _roots([('relpath', 'r', ''), ('path', 'p/p', ''), ('path', '', '')])
480 486 ['r', 'p/p', '.']
481 >>> _roots([('relglob', 'rg*'), ('re', 're/'), ('relre', 'rr')])
487 >>> _roots([('relglob', 'rg*', ''), ('re', 're/', ''), ('relre', 'rr', '')])
482 488 ['.', '.', '.']
483 489 '''
484 490 r = []
485 for kind, pat in kindpats:
491 for kind, pat, source in kindpats:
486 492 if kind == 'glob': # find the non-glob prefix
487 493 root = []
488 494 for p in pat.split('/'):
@@ -497,7 +503,7 b' def _roots(kindpats):'
497 503 return r
498 504
499 505 def _anypats(kindpats):
500 for kind, pat in kindpats:
506 for kind, pat, source in kindpats:
501 507 if kind in ('glob', 're', 'relglob', 'relre', 'set'):
502 508 return True
503 509
General Comments 0
You need to be logged in to leave comments. Login now