From 8497721504bd803b7063e7601fc87d6647e446b4 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 28 Aug 2019 11:19:18 -0400 Subject: [PATCH 1/7] BUG: Do not apply style pre-commit hooks to ThirdParty code --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 45273c09c9d..e3c944da39b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -45,7 +45,7 @@ zap.pl crlf=input # ghostflow-director GitHub automatic check for maximum repository file size * hooks-max-size=100000 Modules/Numerics/FEM/src/dsrc2c.c hooks-max-size=260000 -Modules/ThirdParty/** hooks-max-size=300000 +Modules/ThirdParty/** hooks-max-size=300000 hooks.style= Modules/ThirdParty/NIFTI/src/nifti/nifti2/nifti2_io.c hooks-max-size=400000 Modules/ThirdParty/VNL/src/vxl/v3p/netlib/triangle.c hooks-max-size=670000 Modules/Filtering/Denoising/include/itkPatchBasedDenoisingImageFilter.hxx hooks-max-size=120000 From f9fbd790fd11a9cb38db9a4f6e2a15e28a2496e5 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 28 Aug 2019 11:20:42 -0400 Subject: [PATCH 2/7] BUG: Do not download clang-format with ITK_FORBID_DOWNLOADS enabled --- CMake/ITKModuleClangFormat.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMake/ITKModuleClangFormat.cmake b/CMake/ITKModuleClangFormat.cmake index ad5457db6e5..26831151970 100644 --- a/CMake/ITKModuleClangFormat.cmake +++ b/CMake/ITKModuleClangFormat.cmake @@ -10,6 +10,6 @@ option(ITK_USE_CLANG_FORMAT "Enable the use of clang-format for coding style formatting." ${BUILD_TESTING}) mark_as_advanced(ITK_USE_CLANG_FORMAT) -if(BUILD_TESTING AND ITK_USE_CLANG_FORMAT AND NOT CMAKE_CROSSCOMPILING) +if(BUILD_TESTING AND ITK_USE_CLANG_FORMAT AND NOT CMAKE_CROSSCOMPILING AND NOT ITK_FORBID_DOWNLOADS) include(${ITK_CMAKE_DIR}/../Utilities/ClangFormat/DownloadClangFormat.cmake) endif() From 91b6a600100ec1812be43c82dd024630be05ebce Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 28 Aug 2019 12:07:43 -0400 Subject: [PATCH 3/7] BUG: Add missing KWStyle hook configuration --- Utilities/SetupForDevelopment.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Utilities/SetupForDevelopment.sh b/Utilities/SetupForDevelopment.sh index fde2f503858..d85fa023687 100755 --- a/Utilities/SetupForDevelopment.sh +++ b/Utilities/SetupForDevelopment.sh @@ -51,6 +51,10 @@ messages for interaction with Gerrit. Also, removing the "gerrit" and "stage" re git remote remove stage fi +# Style hook configuration +git config hooks.KWStyle.conf "Utilities/KWStyle/ITK.kws.xml" +git config hooks.KWStyle.overwriteRulesConf "Utilities/KWStyle/ITKOverwrite.txt" + # Make sure we are inside the repository. cd "$(echo "$0"|sed 's/[^/]*$//')"/.. @@ -103,5 +107,5 @@ echo -e "Git version $git_version is OK.\n" # Record the version of this setup so Hooks/pre-commit can check it. -SetupForDevelopment_VERSION=6 +SetupForDevelopment_VERSION=7 git config hooks.SetupForDevelopment ${SetupForDevelopment_VERSION} From 833cb0f95fb8aacbace2cd4b355f0f7096341c2e Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 28 Aug 2019 12:14:07 -0400 Subject: [PATCH 4/7] ENH: Update clang-format binary path configuration This configuration variable is set by ITK/Utilities/ClangFormat/DownloadClangFormat.cmake and ITK/CMake/ITKModuleClangFormat.cmake. --- Utilities/Hooks/pre-commit-style.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Utilities/Hooks/pre-commit-style.bash b/Utilities/Hooks/pre-commit-style.bash index 2a8070a8d92..54d23628519 100644 --- a/Utilities/Hooks/pre-commit-style.bash +++ b/Utilities/Hooks/pre-commit-style.bash @@ -154,13 +154,13 @@ run_KWStyle() { #----------------------------------------------------------------------------- # clangformat. check_for_clangformat() { - clangformat_path=$(git config hooks.clangformat.path) || - clangformat_path=$(which clangformat) || - die "clangformat executable was not found. + clangformat_path=$(git config clangFormat.binary) || + clangformat_path=$(which clang-format) || + die "clang-format executable was not found. Please install clang-format version 8.0 or set the executable location with - git config hooks.clangformat.path /path/to/clang-format + git config clangFormat.binary /path/to/clang-format " } From d3e16ba4f00080c4005edc229f36b1ac8e489019 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 28 Aug 2019 12:37:57 -0400 Subject: [PATCH 5/7] BUG: Fix have_KWStyle detection when running clang-format hook Check before running the hook, which will run, if available. --- Utilities/Hooks/pre-commit-style.bash | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Utilities/Hooks/pre-commit-style.bash b/Utilities/Hooks/pre-commit-style.bash index 54d23628519..bf6a1ebcd85 100644 --- a/Utilities/Hooks/pre-commit-style.bash +++ b/Utilities/Hooks/pre-commit-style.bash @@ -140,6 +140,7 @@ run_KWStyle_on_file() { Line numbers in the errors shown refer to the file: ${1}.kws" fi + return 0 } run_KWStyle() { @@ -239,6 +240,13 @@ run_clangformat_on_file() { } run_clangformat() { + $do_KWStyle && check_for_KWStyle + if test $?; then + have_KWStyle=true + else + have_KWStyle=false + fi + merge_tool=$(get_merge_tool "$merge_tool") || die "Merge tool not configured. Set the merge tool with @@ -254,13 +262,6 @@ For more information, see while read MERGED; do run_clangformat_on_file "$MERGED" || return done # end for changed files - - $do_KWStyle && check_for_KWStyle - if test $?; then - have_KWStyle=false - else - have_KWStyle=true - fi } # Do not run during merge commits for now. From 3afb99a569a81bf2215561b346c6ea4d3e3aef2b Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 28 Aug 2019 14:45:12 -0400 Subject: [PATCH 6/7] BUG: Improvements to pre-commit-style hook for clang-format Various improvements and fixes: - The default merged output is now the output of clang-format. - KWStyle and clangformat style checks are enabled by default. - Console input specification fixed for the mergetool. - Partially staged files without the style hook attributes are automatically skipped. --- Utilities/Hooks/pre-commit-style.bash | 68 +++++++++++++-------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/Utilities/Hooks/pre-commit-style.bash b/Utilities/Hooks/pre-commit-style.bash index bf6a1ebcd85..dae2b646bd0 100644 --- a/Utilities/Hooks/pre-commit-style.bash +++ b/Utilities/Hooks/pre-commit-style.bash @@ -28,18 +28,9 @@ die() { exit 1 } -do_KWStyle=$(git config --bool hooks.KWStyle) || do_KWStyle=false +do_KWStyle=$(git config --bool hooks.KWStyle) || do_KWStyle=true -do_clangformat=$(git config --bool hooks.clangformat) || do_clangformat=false - -if [ "$(uname)" == "Darwin" ]; then - console=" Date: Wed, 28 Aug 2019 16:15:23 -0400 Subject: [PATCH 7/7] ENH: Check for required clang-format version in style hook Suggested-by: Brad King --- Utilities/Hooks/pre-commit-style.bash | 29 ++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Utilities/Hooks/pre-commit-style.bash b/Utilities/Hooks/pre-commit-style.bash index dae2b646bd0..b17009043f8 100644 --- a/Utilities/Hooks/pre-commit-style.bash +++ b/Utilities/Hooks/pre-commit-style.bash @@ -147,14 +147,37 @@ run_KWStyle() { #----------------------------------------------------------------------------- # clangformat. check_for_clangformat() { + clangformat_required_version=8.0.1 + system_tools=" + clang-format-$clangformat_required_version + clang-format +" + for tool in $system_tools; do + if type -p "$tool" >/dev/null; then + system_clang_format="$tool" + break + fi + done clangformat_path=$(git config clangFormat.binary) || - clangformat_path=$(which clang-format) || + clangformat_path=$(type -p "$system_clang_format" >/dev/null) || die "clang-format executable was not found. -Please install clang-format version 8.0 or set the executable location with +Please install clang-format version $clangformat_required_version or set the executable location with + + git config clangFormat.binary /path/to/clang-format +" + if ! "$clangformat_path" --version | grep "clang-format version $clangformat_required_version" >/dev/null 2>/dev/null; then + die "clang-format version $clangformat_required_version is required (exactly) + +Set the path the clang-format $clangformat_required_version executable with git config clangFormat.binary /path/to/clang-format - " + +or disable the clang-format pre-commit hook with + + git config hooks.clangformat false +" + fi } run_clang_format_check_attr()