Print this page
OS-1823 git-pbchk should not depend on mercurial (rich feedback)
*** 28,37 ****
--- 28,39 ----
'''
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,58 ****
syntax = 'regex'
ignore_list = []
lc = 0
! f = open(ignorefile, 'r')
for l in f:
lc += 1
# Remove comments and blank lines
! l = re.sub(r'#.*', '', l).strip()
if l == '':
continue
# Process "syntax:" lines
! m = re.match(r'^syntax:\s*(.*)\s*$', l)
if m:
syntax = m.group(1)
continue
# All other lines are considered patterns
if (syntax == 'glob'):
--- 42,60 ----
syntax = 'regex'
ignore_list = []
lc = 0
! with open(ignorefile, 'r') as f:
for l in f:
lc += 1
# Remove comments and blank lines
! l = l.split('#', 2)[0].strip()
if l == '':
continue
# Process "syntax:" lines
! m = RE_SYNTAX.match(l)
if m:
syntax = m.group(1)
continue
# All other lines are considered patterns
if (syntax == 'glob'):
*** 60,82 ****
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)
# If the ignore files contained no patterns, we'll never ignore
# any paths:
if (len(ignore_list) < 1):
return lambda x: False
--- 62,83 ----
elif (syntax == 'regex'):
ignore_list.append(re.compile(l))
else:
raise Exception('%s:%d: syntax "%s" is not supported' %
(ignorefile, lc, syntax))
!
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.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,92 ****
if (regex.match(path)):
return True
return False
return _ignore_func
-
- # vim: set expandtab sw=4 ts=4:
--- 87,91 ----