TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / tools / pre-commit
blob99553d9927c279bd833fe8a4a95b418d1b19a1c1
1 #!/bin/sh
2 # Copyright 2013, Alexis La Goutte (See AUTHORS file)
4 # For git user: copy tools/pre-commit to .git/hooks/ folder and make it
5 # executable. To bypass it for a single commit, use the --no-verify argument.
6 # Using --no-verify will then fail during git review because of a missing
7 # ChangeID. Fix that by running git review -i. Do not use -i during normal
8 # operation.
10 # Alternatively, invoke it directly with the commit ID. Example for checking the
11 # last commit:
13 # tools/pre-commit HEAD~
15 # Relative paths are also supported. For instance, if you are in epan/, then you
16 # could invoke `../tools/pre-commit HEAD` to check for changes to staged files.
18 # From
19 # http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes
22 # If the commit identifier is not given, use HEAD instead.
23 COMMIT_IDS=HEAD
24 if [ $# -gt 0 ] ; then
25 COMMIT_IDS=$*
28 UNAME=$( uname -a )
30 case "$UNAME" in
31 *\ Msys)
32 pyvar="pythonw.exe"
35 pyvar="python3"
37 esac
39 PYBIN=${WS_GITHOOK_PYTHON:-$pyvar}
41 # Path to hook script in the .git directory
42 hook_script=${GIT_DIR:-.git}/hooks/pre-commit
44 # Always start in the root directory of the source tree, this allows for
45 # invocations via relative paths (such as ../tools/pre-commit):
46 if ! cd "$(git rev-parse --show-toplevel)" ; then
47 echo "Can't change to the top-level source directory."
48 exit 1
51 # Check for newer (actually, different) versions of the pre-commit script
52 # (but only if invoked as hook, i.e. the commit ID is not given as argument).
53 if [ -z "$1" ] && [ -f "$hook_script" ]; then
54 if ! cmp -s "$hook_script" tools/pre-commit; then
55 echo "Pre-commit hook script is outdated, please update! (cp tools/pre-commit ${hook_script})"
59 have_diameter_files="False"
60 bad_alloc_patterns=${PWD}/tools/detect_bad_alloc_patterns.py
61 exit_status=0
63 for COMMIT_ID in $COMMIT_IDS; do
64 COMMIT_FILES=$( git diff-index --cached --name-status "${COMMIT_ID}" | grep -v "^D" | cut -f2 | grep "\\.[ch]$" )
65 if git diff-index --cached --name-status "${COMMIT_ID}" | grep -v "^D" | cut -f2 | grep diameter/ > /dev/null ; then
66 have_diameter_files="True"
69 # Path to filter script in the tools directory
70 filter_script=${PWD}/tools/pre-commit-ignore.py
71 filter_conf=${PWD}/tools/pre-commit-ignore.conf
73 if [ -f "$filter_script" ] && [ -f "$filter_conf" ]; then
74 CHECK_FILES=$( echo "$COMMIT_FILES" | "$PYBIN" "$filter_script" "$filter_conf" ) || continue
75 else
76 CHECK_FILES="$COMMIT_FILES"
79 echo "$COMMIT_FILES" | $PYBIN "$bad_alloc_patterns"
81 # On windows python will output \r\n line endings - we don't want that.
83 # Do not use sed, as not all versions of sed support \r as meaning CR
84 # in a regexp - the only version that does so might be GNU sed; the
85 # GNU sed documentation says that only \n and \\ can be used in a
86 # portable script.
88 # The Single UNIX Specification says that tr supports \r; most if not
89 # all modern UN*Xes should support it.
90 CHECK_FILES=$( echo "$CHECK_FILES" | tr -d '\r' )
92 for FILE in $CHECK_FILES; do
93 # Skip some special cases
94 FILE_BASENAME="$( basename "$FILE" )"
95 # This should only be done on code that's part of one or more
96 # Wireshark programs; idl2wrs.c is a developer tool, not a
97 # Wireshark program, so these tests don't apply.
98 if test "$FILE_BASENAME" = "idl2wrs.c"
99 then
100 continue
102 if test "$FILE_BASENAME" = "wmem_test.c"
103 then
104 continue
107 #Check if checkhf is good
108 ./tools/checkhf.pl "$FILE" || exit_status=1
110 #Check if checkAPIs is good
111 ./tools/checkAPIs.pl -p "$FILE" || exit_status=1
113 #Check if fix-encoding-args is good
114 ./tools/fix-encoding-args.pl "$FILE" || exit_status=1
116 #Check if checkfiltername is good
117 ./tools/checkfiltername.pl "$FILE" || exit_status=1
119 # If there are whitespace errors, print the offending file names and fail. (from git pre-commit.sample)
120 git diff-index --check --cached "${COMMIT_ID}" "$FILE" || exit_status=1
122 done
123 done
125 if [ "$have_diameter_files" = "True" ]
126 then
127 ./tools/validate-diameter-xml.sh > /dev/null || exit_status=1
130 exit $exit_status
133 # Editor modelines
135 # Local Variables:
136 # c-basic-offset: 4
137 # tab-width: 8
138 # indent-tabs-mode: nil
139 # End:
141 # ex: set shiftwidth=4 tabstop=8 expandtab:
142 # :indentSize=4:tabSize=8:noTabs=true: