# HG changeset patch # User Matt Mackall # Date 1243151774 18000 # Node ID 9f12e1a27a1b3b9a5cfea42ea3982b00879607d2 # Parent 7fe2012b3bd0aa2ca362fe6cfed12aa5c83f5574 match: refactor matchfn generation diff -r 7fe2012b3bd0 -r 9f12e1a27a1b mercurial/match.py --- 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)