Submitter | Durham Goode |
---|---|
Date | May 20, 2015, 9:57 p.m. |
Message ID | <28ac58249dbc906622e3.1432159054@dev2000.prn2.facebook.com> |
Download | mbox | patch |
Permalink | /patch/9198/ |
State | Accepted |
Commit | 714f612f2afc4b43876f36ca7fa5e3871e4f4bb2 |
Headers | show |
Comments
I'm pushing the first two patches to the clowncopter for now. Thanks. On Wed, May 20, 2015 at 2:58 PM Durham Goode <durham@fb.com> wrote: > # HG changeset patch > # User Durham Goode <durham@fb.com> > # Date 1431818178 25200 > # Sat May 16 16:16:18 2015 -0700 > # Node ID 28ac58249dbc906622e368357daadd4814f9c71c > # Parent aed26cd32a07f5e18065a521b4bc42afff2ccc5a > match: allow unioning arbitrary match functions > > A future patch will be allowing nested matchers. To support that, let's > refactor > _buildmatch to build a list of matchers then return True if any match. > > We were already doing that for filesets + regex patterns, but this way > will be > more generic. > > diff --git a/mercurial/match.py b/mercurial/match.py > --- a/mercurial/match.py > +++ b/mercurial/match.py > @@ -453,14 +453,21 @@ def _regex(kind, pat, globsuffix): > def _buildmatch(ctx, kindpats, globsuffix, listsubrepos, root): > '''Return regexp string and a matcher function for kindpats. > globsuffix is appended to the regexp of globs.''' > + matchfuncs = [] > + > fset, kindpats = _expandsets(kindpats, ctx, listsubrepos) > - if not kindpats: > - return "", fset.__contains__ > + if fset: > + matchfuncs.append(fset.__contains__) > > - regex, mf = _buildregexmatch(kindpats, globsuffix) > - if fset: > - return regex, lambda f: f in fset or mf(f) > - return regex, mf > + regex = '' > + if kindpats: > + regex, mf = _buildregexmatch(kindpats, globsuffix) > + matchfuncs.append(mf) > + > + if len(matchfuncs) == 1: > + return regex, matchfuncs[0] > + else: > + return regex, lambda f: any(mf(f) for mf in matchfuncs) > > def _buildregexmatch(kindpats, globsuffix): > """Build a match function from a list of kinds and kindpats, > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@selenic.com > http://selenic.com/mailman/listinfo/mercurial-devel >
Patch
diff --git a/mercurial/match.py b/mercurial/match.py --- a/mercurial/match.py +++ b/mercurial/match.py @@ -453,14 +453,21 @@ def _regex(kind, pat, globsuffix): def _buildmatch(ctx, kindpats, globsuffix, listsubrepos, root): '''Return regexp string and a matcher function for kindpats. globsuffix is appended to the regexp of globs.''' + matchfuncs = [] + fset, kindpats = _expandsets(kindpats, ctx, listsubrepos) - if not kindpats: - return "", fset.__contains__ + if fset: + matchfuncs.append(fset.__contains__) - regex, mf = _buildregexmatch(kindpats, globsuffix) - if fset: - return regex, lambda f: f in fset or mf(f) - return regex, mf + regex = '' + if kindpats: + regex, mf = _buildregexmatch(kindpats, globsuffix) + matchfuncs.append(mf) + + if len(matchfuncs) == 1: + return regex, matchfuncs[0] + else: + return regex, lambda f: any(mf(f) for mf in matchfuncs) def _buildregexmatch(kindpats, globsuffix): """Build a match function from a list of kinds and kindpats,