Print this page
OS-1823 git-pbchk should not depend on mercurial (rich feedback)
@@ -28,10 +28,12 @@
'''
import re
import fnmatch
+RE_SYNTAX = re.compile(r'^syntax:\s*(.*)\s*$')
+
#
# It is important that this module not rely on Mercurial
#
def _read_ignore_file(ignorefile):
@@ -40,19 +42,19 @@
syntax = 'regex'
ignore_list = []
lc = 0
- f = open(ignorefile, 'r')
+ with open(ignorefile, 'r') as f:
for l in f:
lc += 1
# Remove comments and blank lines
- l = re.sub(r'#.*', '', l).strip()
+ l = l.split('#', 2)[0].strip()
if l == '':
continue
# Process "syntax:" lines
- m = re.match(r'^syntax:\s*(.*)\s*$', l)
+ m = RE_SYNTAX.match(l)
if m:
syntax = m.group(1)
continue
# All other lines are considered patterns
if (syntax == 'glob'):
@@ -60,23 +62,22 @@
elif (syntax == 'regex'):
ignore_list.append(re.compile(l))
else:
raise Exception('%s:%d: syntax "%s" is not supported' %
(ignorefile, lc, syntax))
- f.close()
+
return ignore_list
-
def ignore(root, ignorefiles):
# If we aren't provided any ignore files, we'll never ignore
# any paths:
if (len(ignorefiles) < 1):
return lambda x: False
ignore_list = []
for ignorefile in ignorefiles:
- ignore_list += _read_ignore_file(ignorefile)
+ ignore_list.extend(_read_ignore_file(ignorefile))
# If the ignore files contained no patterns, we'll never ignore
# any paths:
if (len(ignore_list) < 1):
return lambda x: False
@@ -86,7 +87,5 @@
if (regex.match(path)):
return True
return False
return _ignore_func
-
-# vim: set expandtab sw=4 ts=4: