diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2016-01-30 03:49:41 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2016-02-25 12:34:50 +0000 |
commit | fe1de0146e607652333e729d6c11f43584744785 (patch) | |
tree | 6e8d2a38f50bb822fff6b08ff4a58d6c1b2d6f7f /tools/pre-commit | |
parent | fd9e71d15d4023438deb51b043332d61f7f5207c (diff) |
pre-commit: Avoid launching python subprocesses.
This makes Python required only for (portable) fnmatch().
Change the ignore script to work as a filter.
Multi-platform improvements.
Change-Id: I6ac757d48ba2ff965da5da3dc9c25047a0e37f92
Reviewed-on: https://code.wireshark.org/review/13693
Reviewed-by: Michael Mann <mmann78@netscape.net>
Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'tools/pre-commit')
-rwxr-xr-x | tools/pre-commit | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/tools/pre-commit b/tools/pre-commit index 796eb5e4ee..14f3cd2156 100755 --- a/tools/pre-commit +++ b/tools/pre-commit @@ -19,12 +19,22 @@ # If the commit identifier is not given, use HEAD instead. COMMIT_ID="${1:-HEAD}" +UNAME=`uname -o` + +case "$UNAME" in + Msys) + pyvar="pythonw.exe" + ;; + *) + pyvar="python" + ;; +esac + +PYBIN=${WS_GITHOOK_PYTHON:-$pyvar} + # Path to hook script in the .git directory hook_script=${GIT_DIR:-.git}/hooks/pre-commit -# Path to check script in the tools directory -check_script=./tools/pre-commit-check.py - # Always start in the root directory of the source tree, this allows for # invocations via relative paths (such as ../tools/pre-commit): cd "$(git rev-parse --show-toplevel)" @@ -37,14 +47,41 @@ fi exit_status=0 -if [ -e "$check_script" ] -then - python "$check_script" ${COMMIT_ID} || exit_status=1 -else - echo "File '$check_script' not found. Aborting." +COMMIT_FILES=`git diff-index --cached --name-status ${COMMIT_ID} | grep -v "^D" | cut -f2 | grep "\.[ch]$"` + +# Path to filter script in the tools directory +filter_script=${PWD}/tools/pre-commit-ignore.py +filter_conf=${PWD}/tools/pre-commit-ignore.conf + +if [ ! -e "$filter_script" ]; then + echo "File '$filter_script' does not exist. Aborting." + exit 1 +fi + +CHECK_FILES=`echo "$COMMIT_FILES" | "$PYBIN" "$filter_script" "$filter_conf"` +if [ $? -ne 0 ]; then exit 1 fi +# On windows python will output \r\n line endings - we don't want that +CHECK_FILES=`echo "$CHECK_FILES" | sed 's/\r//g'` + +for FILE in $CHECK_FILES; do + + #Check if checkhf is good + ./tools/checkhf.pl $FILE || exit_status=1 + + #Check if checkAPIs is good + ./tools/checkAPIs.pl -p $FILE || exit_status=1 + + #Check if fix-encoding-args is good + ./tools/fix-encoding-args.pl $FILE || exit_status=1 + + #Check if checkfiltername is good + ./tools/checkfiltername.pl $FILE || exit_status=1 + +done + # If there are whitespace errors, print the offending file names and fail. (from git pre-commit.sample) git diff-index --check --cached ${COMMIT_ID} || exit_status=1 |