Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 4190:769bc4af561d
util.*matcher: change default "names" argument
names=['.'] means "include (recursively) only files from the current subdir";
the function then did a hack to walk the whole tree. Clean that up.
This also fixes a problem where "--include ." works in a subdir, but not
on the tree root.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Sat, 10 Mar 2007 23:00:51 -0300 |
parents | b1716a1f79c4 |
children | 9814d600011e |
comparison
equal
deleted
inserted
replaced
4189:b1716a1f79c4 | 4190:769bc4af561d |
---|---|
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=[], head='', src=None): |
382 return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src) | 382 return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src) |
383 | 383 |
384 def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', | 384 def cmdmatcher(canonroot, cwd='', names=[], inc=[], exc=[], head='', |
385 src=None, globbed=False): | 385 src=None, globbed=False): |
386 if not globbed: | 386 if not globbed: |
387 names = expand_glob(names) | 387 names = expand_glob(names) |
388 return _matcher(canonroot, cwd, names, inc, exc, head, 'relpath', src) | 388 return _matcher(canonroot, cwd, names, inc, exc, head, 'relpath', src) |
389 | 389 |
426 if c in _globchars: return True | 426 if c in _globchars: return True |
427 return False | 427 return False |
428 | 428 |
429 def regex(kind, name, tail): | 429 def regex(kind, name, tail): |
430 '''convert a pattern into a regular expression''' | 430 '''convert a pattern into a regular expression''' |
431 if not name: | |
432 return '' | |
431 if kind == 're': | 433 if kind == 're': |
432 return name | 434 return name |
433 elif kind == 'path': | 435 elif kind == 'path': |
434 return '^' + re.escape(name) + '(?:/|$)' | 436 return '^' + re.escape(name) + '(?:/|$)' |
435 elif kind == 'relglob': | 437 elif kind == 'relglob': |
475 files = [] | 477 files = [] |
476 roots = [] | 478 roots = [] |
477 for kind, name in [patkind(p, dflt_pat) for p in names]: | 479 for kind, name in [patkind(p, dflt_pat) for p in names]: |
478 if kind in ('glob', 'relpath'): | 480 if kind in ('glob', 'relpath'): |
479 name = canonpath(canonroot, cwd, name) | 481 name = canonpath(canonroot, cwd, name) |
480 if name == '': | |
481 kind, name = 'glob', '**' | |
482 elif kind in ('relglob', 'path'): | 482 elif kind in ('relglob', 'path'): |
483 name = normpath(name) | 483 name = normpath(name) |
484 if kind in ('glob', 're', 'relglob'): | 484 if kind in ('glob', 're', 'relglob'): |
485 pats.append((kind, name)) | 485 pats.append((kind, name)) |
486 if kind == 'glob': | 486 if kind == 'glob': |
507 lambda fn: (incmatch(fn) and not excmatch(fn) and | 507 lambda fn: (incmatch(fn) and not excmatch(fn) and |
508 (fn.endswith('/') or | 508 (fn.endswith('/') or |
509 (not pats and not files) or | 509 (not pats and not files) or |
510 (pats and patmatch(fn)) or | 510 (pats and patmatch(fn)) or |
511 (files and filematch(fn)))), | 511 (files and filematch(fn)))), |
512 (inc or exc or (pats and pats != [('glob', '**')])) and True) | 512 (inc or exc or pats) and True) |
513 | 513 |
514 def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): | 514 def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): |
515 '''enhanced shell command execution. | 515 '''enhanced shell command execution. |
516 run with environment maybe modified, maybe in different dir. | 516 run with environment maybe modified, maybe in different dir. |
517 | 517 |