mq: find_series() simplify and don't use regexps
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Sun, 14 Mar 2010 12:08:14 +0100
changeset 10685 10248fc845db
parent 10684 485c1d7f8a77
child 10686 0c68c2c36ed8
mq: find_series() simplify and don't use regexps
hgext/mq.py
--- a/hgext/mq.py	Sun Mar 14 11:12:51 2010 +0100
+++ b/hgext/mq.py	Sun Mar 14 12:08:14 2010 +0100
@@ -328,16 +328,12 @@
         return os.path.join(self.path, *p)
 
     def find_series(self, patch):
-        pre = re.compile("(\s*)([^#]+)")
-        index = 0
-        for l in self.full_series:
-            m = pre.match(l)
-            if m:
-                s = m.group(2)
-                s = s.rstrip()
-                if s == patch:
-                    return index
-            index += 1
+        def matchpatch(l):
+            l = l.split('#', 1)[0]
+            return l.strip() == patch
+        for index, l in enumerate(self.full_series):
+            if matchpatch(l):
+                return index
         return None
 
     guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)')