changeset 1446:4babaa52badf

abort on invalid pattern in matcher
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Tue, 25 Oct 2005 14:58:11 -0700
parents 56281e086f38
children 508a3f559553
files mercurial/util.py
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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'''