Revert "drsuapi_dissect_element_DsGetNCChangesCtr6TS_ctr6 dissect_krb5_PAC_NDRHEADERBLOB"
[wireshark-sm.git] / tools / pre-commit
blobbe74103d01c83054d6b7b7a3265b19c9c5309004
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_ID="${1:-HEAD}"
25 UNAME=$( uname -a )
27 case "$UNAME" in
28 *\ Msys)
29 pyvar="pythonw.exe"
32 pyvar="python3"
34 esac
36 PYBIN=${WS_GITHOOK_PYTHON:-$pyvar}
38 # Path to hook script in the .git directory
39 hook_script=${GIT_DIR:-.git}/hooks/pre-commit
41 # Always start in the root directory of the source tree, this allows for
42 # invocations via relative paths (such as ../tools/pre-commit):
43 if ! cd "$(git rev-parse --show-toplevel)" ; then
44 echo "Can't change to the top-level source directory."
45 exit 1
48 # Check for newer (actually, different) versions of the pre-commit script
49 # (but only if invoked as hook, i.e. the commit ID is not given as argument).
50 if [ -z "$1" ] && [ -f "$hook_script" ]; then
51 if ! cmp -s "$hook_script" tools/pre-commit; then
52 echo "Pre-commit hook script is outdated, please update! (cp tools/pre-commit ${hook_script})"
56 exit_status=0
58 COMMIT_FILES=$( git diff-index --cached --name-status "${COMMIT_ID}" | grep -v "^D" | cut -f2 | grep "\\.[ch]$" )
59 DIAMETER_FILES=$( git diff-index --cached --name-status "${COMMIT_ID}" | grep -v "^D" | cut -f2 | grep diameter/ )
61 # Path to filter script in the tools directory
62 filter_script=${PWD}/tools/pre-commit-ignore.py
63 filter_conf=${PWD}/tools/pre-commit-ignore.conf
65 if [ -f "$filter_script" ] && [ -f "$filter_conf" ]; then
66 CHECK_FILES=$( echo "$COMMIT_FILES" | "$PYBIN" "$filter_script" "$filter_conf" ) || exit
67 else
68 CHECK_FILES="$COMMIT_FILES"
71 bad_alloc_patterns=${PWD}/tools/detect_bad_alloc_patterns.py
72 echo "$COMMIT_FILES" | $PYBIN "$bad_alloc_patterns"
74 # On windows python will output \r\n line endings - we don't want that.
76 # Do not use sed, as not all versions of sed support \r as meaning CR
77 # in a regexp - the only version that does so might be GNU sed; the
78 # GNU sed documentation says that only \n and \\ can be used in a
79 # portable script.
81 # The Single UNIX Specification says that tr supports \r; most if not
82 # all modern UN*Xes should support it.
83 CHECK_FILES=$( echo "$CHECK_FILES" | tr -d '\r' )
85 for FILE in $CHECK_FILES; do
86 # Skip some special cases
87 FILE_BASENAME="$( basename "$FILE" )"
88 # This should only be done on code that's part of one or more
89 # Wireshark programs; idl2wrs.c is a developer tool, not a
90 # Wireshark program, so these tests don't apply.
91 if test "$FILE_BASENAME" = "idl2wrs.c"
92 then
93 continue
95 if test "$FILE_BASENAME" = "wmem_test.c"
96 then
97 continue
100 #Check if checkhf is good
101 ./tools/checkhf.pl "$FILE" || exit_status=1
103 #Check if checkAPIs is good
104 ./tools/checkAPIs.pl -p "$FILE" || exit_status=1
106 #Check if fix-encoding-args is good
107 ./tools/fix-encoding-args.pl "$FILE" || exit_status=1
109 #Check if checkfiltername is good
110 ./tools/checkfiltername.pl "$FILE" || exit_status=1
112 # If there are whitespace errors, print the offending file names and fail. (from git pre-commit.sample)
113 git diff-index --check --cached "${COMMIT_ID}" "$FILE" || exit_status=1
115 done
117 if [ "x$DIAMETER_FILES" != x ]
118 then
119 ./tools/validate-diameter-xml.sh > /dev/null || exit_status=1
122 exit $exit_status
125 # Editor modelines
127 # Local Variables:
128 # c-basic-offset: 4
129 # tab-width: 8
130 # indent-tabs-mode: nil
131 # End:
133 # ex: set shiftwidth=4 tabstop=8 expandtab:
134 # :indentSize=4:tabSize=8:noTabs=true: