5 Make sure you do not commit TAB, CRLF, ... in matching pattern files. 7 .gitconfig configuration : 10 hooks = crlf tab digraphs doxygen 13 crlf= *.cpp *.hpp *.xml 14 lgpl= *.cpp *.hpp *.xml 17 To do the same check on a server to prevent CRLF/CR from being 20 Default file pattern is '*'. To specify patterns to check : 25 from functools
import partial
29 CRLF =
lambda x:
'\r\n' in x
30 CR =
lambda x:
'\r' in x
31 TAB =
lambda x:
'\t' in x
32 LGPL =
lambda x:
'Lesser General Public License' in x
33 BSD =
lambda x:
'under the terms of the BSD Licence' in x
34 SLM_LOG =
lambda x: bool(
35 (
'O''SLM_LOG' in x)
and not (re.search(
'#define O''SLM_LOG', x)
and x.count(
'O''SLM_LOG') == 1)
37 DIGRAPH =
lambda x:
"<:" in x
or ":>" in x
38 DOXYGEN =
lambda x:
'* @class' in x
or '* @date' in x
or '* @namespace' in x
39 COPAIN =
lambda x:
'copain' in x
42 'crlf': (CRLF,
'CRLF line endings',
'*.cpp *.hpp *.hxx *.cxx *.c *.h *.xml *.txt *.cmake *.py'),
43 'cr': (CR,
'CR line endings',
'*.cpp *.hpp *.hxx *.cxx *.c *.h *.xml *.txt *.cmake *.py'),
44 'tab': (TAB,
'TAB',
'*.cpp *.hpp *.hxx *.cxx *.c *.h *.xml *.txt *.cmake *.py'),
45 'lgpl': (LGPL,
'LGPL Header',
'*.cpp *.hpp *.hxx *.cxx *.c *.h *.xml *.txt *.cmake'),
46 'bsd': (BSD,
'BSD Header',
'*.cpp *.hpp *.hxx *.cxx *.c *.h *.xml *.txt *.cmake'),
47 'oslmlog': (SLM_LOG,
'O''SLM_LOG',
'*.cpp *.hpp *.hxx *.cxx *.c *.h'),
48 'digraphs': (DIGRAPH,
'Forbiden digraphs: <'':, :''>',
'*.cpp *.hpp *.hxx *.cxx *.c *.h'),
49 'doxygen': (DOXYGEN,
'@class @date @namespace doxygen tag(s)',
'*.cpp *.hpp *.hxx *.cxx *.c *.h'),
50 'copain': (COPAIN,
'copain',
'*.cpp *.hpp *.hxx *.cxx *.c *.h'),
53 WARNING = (
'Attempt to commit or push text file(s) containing "%s"')
54 FILEWARN = (
' - %s:%s')
58 include_patterns =
common.get_option(
'forbidtoken-hook.' + config_name, default=tr[config_name][2]).split()
60 common.note(
'Checking for "' + config_name +
'" tokens on ' +
', '.join(include_patterns) +
' files')
62 token = tr[config_name][0]
63 line_iter =
lambda x: enumerate(re.finditer(
".*\n", x, re.MULTILINE), 1)
64 line_match =
lambda test, x: (n
for n, m
in line_iter(x)
if test(m.group()))
68 if not any(f.fnmatch(p)
for p
in include_patterns):
75 for n
in line_match(token, content):
89 [(name, partial(forbidtoken, config_name=name))
for name
in tr]
def get_option(option, default, type="")