[projects/git-slug: 24/170] Translate fnmatch patterns to regexps
glen
glen at pld-linux.org
Mon Sep 21 21:40:49 CEST 2015
commit d80dfa5310446a06adaca10c05de7477df147b6e
Author: Kacper Kornet <draenog at pld-linux.org>
Date: Mon Sep 19 03:08:02 2011 +0100
Translate fnmatch patterns to regexps
It seems to be faster that way.
git_slug/refsdata.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/git_slug/refsdata.py b/git_slug/refsdata.py
index 41f45fe..b471722 100644
--- a/git_slug/refsdata.py
+++ b/git_slug/refsdata.py
@@ -2,6 +2,7 @@
import collections
import fnmatch
import os
+import re
from .gitconst import EMPTYSHA1, REFFILE, REFREPO, GITSERVER
from .gitrepo import GitRepo
@@ -12,12 +13,13 @@ class RemoteRefsError(Exception):
class RemoteRefsData:
def __init__(self, stream, pattern, dirpattern='*'):
self.heads = collections.defaultdict(lambda: collections.defaultdict(lambda: EMPTYSHA1))
- refpatterns = list(os.path.join('refs/heads', p) for p in pattern)
+ pats = re.compile('|'.join(fnmatch.translate(os.path.join('refs/heads', p)) for p in pattern))
+ dirpat=re.compile(fnmatch.translate(dirpattern))
for line in stream.readlines():
if isinstance(line, bytes):
line = line.decode("utf-8")
(sha1, ref, repo) = line.split()
- if any(fnmatch.fnmatchcase(ref, p) for p in refpatterns) and fnmatch.fnmatchcase(repo, dirpattern):
+ if pats.match(ref) and dirpat.match(repo):
self.heads[repo][ref] = sha1
def put(self, repo, data):
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/git-slug.git/commitdiff/4ed64f73960519a2f4fd04c42950b2c96ae795c5
More information about the pld-cvs-commit
mailing list