]> asedeno.scripts.mit.edu Git - git-svn-keywords.git/commitdiff
Optimize ignores matching
authorAlejandro R. Sedeño <asedeno@mit.edu>
Fri, 27 Aug 2010 18:26:50 +0000 (14:26 -0400)
committerAlejandro R. Sedeño <asedeno@mit.edu>
Fri, 27 Aug 2010 18:38:28 +0000 (14:38 -0400)
Compile regular expressions for each ignore once, rather than for each
file we're looking at.

git-svn-keywords.py

index 1bbc494d388a1f4ab4cc2295673925b7755da6f2..4624e2f26fe55a3cda30c510dbb97aeec6700093 100755 (executable)
@@ -29,10 +29,10 @@ from __future__ import with_statement
 import errno, os, re, urllib
 from ConfigParser import ConfigParser
 from optparse import OptionParser
-from fnmatch import fnmatch
+import fnmatch
 import git
 
-VERSION = "0.9.1"
+VERSION = "0.9.2"
 
 # Where we keep data in the repo.
 def gsk(g):
@@ -216,8 +216,9 @@ def smudge(g, options):
     ignores = []
     with open(os.path.join(g.wd,'.git','info','exclude')) as f:
         for line in f:
-            if line[0] != '#':
-                ignores.append(line.rstrip('\n'))
+            line = line.rstrip('\n')
+            if line and line[0] != '#':
+                ignores.append(re.compile(fnmatch.translate(line)))
 
     paths = FILES.sections()
     paths.sort()
@@ -227,8 +228,9 @@ def smudge(g, options):
 
         ignore = False
         for i in ignores:
-            if fnmatch(path, i):
+            if i.match(path):
                 ignore = True
+                break
         if ignore:
             continue
         try: