Patchwork [1,of,5] check-code: only fix patterns once

login
register
mail settings
Submitter Simon Heimberg
Date June 8, 2013, 6:56 p.m.
Message ID <e32bdfb08c8ff96f9f50.1370717819@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/1714/
State Accepted
Commit 5443d40d524b41d1e3ef63973806260e1e97ffbe
Headers show

Comments

Simon Heimberg - June 8, 2013, 6:56 p.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1370715614 -7200
# Node ID e32bdfb08c8ff96f9f50bfb60888c187830e3ac6
# Parent  872f284aa54a17e62391de184cd5b1b586277101
check-code: only fix patterns once

The patterns were fixed once for every file. Now only do it once when loading
the file.

Patch

diff -r 872f284aa54a -r e32bdfb08c8f contrib/check-code.py
--- a/contrib/check-code.py	Mit Jun 05 22:41:53 2013 +0200
+++ b/contrib/check-code.py	Sam Jun 08 20:20:14 2013 +0200
@@ -317,6 +317,22 @@ 
     ('txt', r'.*\.txt$', txtfilters, txtpats),
 ]
 
+def _preparepats():
+    for c in checks:
+        failandwarn = c[-1]
+        for pats in failandwarn:
+            for i, pseq in enumerate(pats):
+                # fix-up regexes for multi-line searches
+                po = p = pseq[0]
+                # \s doesn't match \n
+                p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p)
+                # [^...] doesn't match newline
+                p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p)
+
+                #print po, '=>', p
+                pats[i] = (p,) + pseq[1:]
+_preparepats()
+
 class norepeatlogger(object):
     def __init__(self):
         self._lastseen = None
@@ -403,15 +419,6 @@ 
                 p, msg = pat
                 ignore = None
 
-            # fix-up regexes for multi-line searches
-            po = p
-            # \s doesn't match \n
-            p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p)
-            # [^...] doesn't match newline
-            p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p)
-
-            #print po, '=>', p
-
             pos = 0
             n = 0
             for m in re.finditer(p, post, re.MULTILINE):