Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 4197:492d0d5b6976
remove unused "head" hack from util._matcher
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Sat, 10 Mar 2007 23:00:59 -0300 |
parents | e8ee8fdeddb1 |
children | 9e3121017fb2 |
comparison
equal
deleted
inserted
replaced
4196:1c69c73d85d9 | 4197:492d0d5b6976 |
---|---|
376 break | 376 break |
377 name = dirname | 377 name = dirname |
378 | 378 |
379 raise Abort('%s not under root' % myname) | 379 raise Abort('%s not under root' % myname) |
380 | 380 |
381 def matcher(canonroot, cwd='', names=[], inc=[], exc=[], head='', src=None): | 381 def matcher(canonroot, cwd='', names=[], inc=[], exc=[], src=None): |
382 return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src) | 382 return _matcher(canonroot, cwd, names, inc, exc, 'glob', src) |
383 | 383 |
384 def cmdmatcher(canonroot, cwd='', names=[], inc=[], exc=[], head='', | 384 def cmdmatcher(canonroot, cwd='', names=[], inc=[], exc=[], src=None, |
385 src=None, globbed=False, default=None): | 385 globbed=False, default=None): |
386 default = default or 'relpath' | 386 default = default or 'relpath' |
387 if default == 'relpath' and not globbed: | 387 if default == 'relpath' and not globbed: |
388 names = expand_glob(names) | 388 names = expand_glob(names) |
389 return _matcher(canonroot, cwd, names, inc, exc, head, default, src) | 389 return _matcher(canonroot, cwd, names, inc, exc, default, src) |
390 | 390 |
391 def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src): | 391 def _matcher(canonroot, cwd, names, inc, exc, dflt_pat, src): |
392 """build a function to match a set of file patterns | 392 """build a function to match a set of file patterns |
393 | 393 |
394 arguments: | 394 arguments: |
395 canonroot - the canonical root of the tree you're matching against | 395 canonroot - the canonical root of the tree you're matching against |
396 cwd - the current working directory, if relevant | 396 cwd - the current working directory, if relevant |
397 names - patterns to find | 397 names - patterns to find |
398 inc - patterns to include | 398 inc - patterns to include |
399 exc - patterns to exclude | 399 exc - patterns to exclude |
400 head - a regex to prepend to patterns to control whether a match is rooted | |
401 dflt_pat - if a pattern in names has no explicit type, assume this one | 400 dflt_pat - if a pattern in names has no explicit type, assume this one |
402 src - where these patterns came from (e.g. .hgignore) | 401 src - where these patterns came from (e.g. .hgignore) |
403 | 402 |
404 a pattern is one of: | 403 a pattern is one of: |
405 'glob:<glob>' - a glob relative to cwd | 404 'glob:<glob>' - a glob relative to cwd |
415 - list of roots (places where one should start a recursive walk of the fs); | 414 - list of roots (places where one should start a recursive walk of the fs); |
416 this often matches the explicit non-pattern names passed in, but also | 415 this often matches the explicit non-pattern names passed in, but also |
417 includes the initial part of glob: patterns that has no glob characters | 416 includes the initial part of glob: patterns that has no glob characters |
418 - a bool match(filename) function | 417 - a bool match(filename) function |
419 - a bool indicating if any patterns were passed in | 418 - a bool indicating if any patterns were passed in |
420 | |
421 todo: | |
422 make head regex a rooted bool | |
423 """ | 419 """ |
424 | 420 |
425 def contains_glob(name): | 421 def contains_glob(name): |
426 for c in name: | 422 for c in name: |
427 if c in _globchars: return True | 423 if c in _globchars: return True |
434 if kind == 're': | 430 if kind == 're': |
435 return name | 431 return name |
436 elif kind == 'path': | 432 elif kind == 'path': |
437 return '^' + re.escape(name) + '(?:/|$)' | 433 return '^' + re.escape(name) + '(?:/|$)' |
438 elif kind == 'relglob': | 434 elif kind == 'relglob': |
439 return head + globre(name, '(?:|.*/)', '(?:/|$)') | 435 return globre(name, '(?:|.*/)', '(?:/|$)') |
440 elif kind == 'relpath': | 436 elif kind == 'relpath': |
441 return head + re.escape(name) + '(?:/|$)' | 437 return re.escape(name) + '(?:/|$)' |
442 elif kind == 'relre': | 438 elif kind == 'relre': |
443 if name.startswith('^'): | 439 if name.startswith('^'): |
444 return name | 440 return name |
445 return '.*' + name | 441 return '.*' + name |
446 return head + globre(name, '', tail) | 442 return globre(name, '', tail) |
447 | 443 |
448 def matchfn(pats, tail): | 444 def matchfn(pats, tail): |
449 """build a matching function from a set of patterns""" | 445 """build a matching function from a set of patterns""" |
450 if not pats: | 446 if not pats: |
451 return | 447 return |