abort on invalid pattern in matcher
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Tue, 25 Oct 2005 14:58:11 -0700
changeset 1446 4babaa52badf
parent 1445 56281e086f38
child 1447 508a3f559553
abort on invalid pattern in matcher
mercurial/util.py
--- a/mercurial/util.py	Tue Oct 25 14:57:14 2005 -0700
+++ b/mercurial/util.py	Tue Oct 25 14:58:11 2005 -0700
@@ -246,9 +246,21 @@
 
     def matchfn(pats, tail):
         """build a matching function from a set of patterns"""
-        if pats:
-            pat = '(?:%s)' % '|'.join([regex(k, p, tail) for (k, p) in pats])
-            return re.compile(pat).match
+        matches = []
+        for k, p in pats:
+            try:
+                pat = '(?:%s)' % regex(k, p, tail)
+                matches.append(re.compile(pat).match)
+            except re.error, inst:
+                raise Abort("invalid pattern: %s:%s" % (k, p))
+
+        def buildfn(text):
+            for m in matches:
+                r = m(text)
+                if r:
+                    return r
+
+        return buildfn
 
     def globprefix(pat):
         '''return the non-glob prefix of a path, e.g. foo/* -> foo'''