Mercurial > hg-stable
changeset 8571:9f12e1a27a1b
match: refactor matchfn generation
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 24 May 2009 02:56:14 -0500 |
parents | 7fe2012b3bd0 |
children | dd46948a07fa |
files | mercurial/match.py |
diffstat | 1 files changed, 24 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/match.py Sun May 24 02:56:14 2009 -0500 +++ b/mercurial/match.py Sun May 24 02:56:14 2009 -0500 @@ -148,7 +148,7 @@ # a common case: no patterns at all if not names and not inc and not exc: - return [], util.always, False + return [], lambda f: True, False def contains_glob(name): for c in name: @@ -233,20 +233,35 @@ roots, pats, anypats = normalizepats(names, dflt_pat) - patmatch = matchfn(pats, '$') or util.always - incmatch = util.always + patmatch = matchfn(pats, '$') if inc: dummy, inckinds, dummy = normalizepats(inc, 'glob') incmatch = matchfn(inckinds, '(?:/|$)') - excmatch = util.never if exc: dummy, exckinds, dummy = normalizepats(exc, 'glob') excmatch = matchfn(exckinds, '(?:/|$)') - if not names and inc and not exc: - # common case: hgignore patterns - matcher = incmatch + if names: + if inc: + if exc: + m = lambda f: incmatch(f) and not excmatch(f) and patmatch(f) + else: + m = lambda f: incmatch(f) and patmatch(f) + else: + if exc: + m = lambda f: not excmatch(f) and patmatch(f) + else: + m = patmatch else: - matcher = lambda fn: incmatch(fn) and not excmatch(fn) and patmatch(fn) + if inc: + if exc: + m = lambda f: incmatch(f) and not excmatch(f) + else: + m = incmatch + else: + if exc: + m = lambda f: not excmatch(f) + else: + m = lambda f: True - return (roots, matcher, (inc or exc or anypats) and True) + return (roots, m, (inc or exc or anypats) and True)