changeset 25239:714f612f2afc

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.
author Durham Goode <durham@fb.com>
date Sat, 16 May 2015 16:16:18 -0700
parents 5a55ad6e8e24
children a415e94fd34f
files mercurial/match.py
diffstat 1 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/match.py	Sat May 16 16:12:00 2015 -0700
+++ b/mercurial/match.py	Sat May 16 16:16:18 2015 -0700
@@ -479,14 +479,21 @@
 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,