[Cmake-commits] CMake branch, hooks, updated. 2dbbb6ff4e0d55558865abdb540c368b1d4e208a

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Nov 16 17:05:22 EST 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, hooks has been updated
       via  2dbbb6ff4e0d55558865abdb540c368b1d4e208a (commit)
       via  b32ecce759213ca7e8214d0ad014660f9c834bbb (commit)
       via  c46078635786f5254f7262a580f2f16a620d78bf (commit)
       via  d5bb076453719934cd9eda65e72d337acb4fe5bd (commit)
      from  19f86ec15cc36f3edd30210724b0d11b080d9961 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2dbbb6ff4e0d55558865abdb540c368b1d4e208a
commit 2dbbb6ff4e0d55558865abdb540c368b1d4e208a
Merge: c460786 b32ecce
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Fri Nov 5 15:47:20 2010 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Fri Nov 5 15:47:20 2010 -0400

    Merge branch 'kwstyle-non-blocking' into hooks


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b32ecce759213ca7e8214d0ad014660f9c834bbb
commit b32ecce759213ca7e8214d0ad014660f9c834bbb
Author:     Gaëtan Lehmann <gaetan.lehmann at jouy.inra.fr>
AuthorDate: Wed Oct 27 17:02:19 2010 +0200
Commit:     Matt McCormick (thewtex) <matt at mmmccormick.com>
CommitDate: Wed Nov 3 20:54:00 2010 -0500

    make the check for KWStyle executable non blocking
    
    At this time, a contributor won't be able to commit a change if KWStyle
    is not installed on the computer. KWStyle is not a very common program,
    and so is likely to have to be installed by hand. This increase the work
    needed to be able to contribute to ITK.
    With this change a warning is displayed if KWStyle is not installed
    but the commit is not blocked.
    
    Change-Id: I0719ee5ac6e048120504bbdc4dc022043c0f0ded

diff --git a/pre-commit-style b/pre-commit-style
index 15af958..7fc51c8 100644
--- a/pre-commit-style
+++ b/pre-commit-style
@@ -77,15 +77,20 @@ Allow skipping the style check for this commit with
 # KWStyle.
 check_for_KWStyle() {
 	KWStyle_path=$(git config hooks.KWStyle.path) ||
-	KWStyle_path=$(which KWStyle) ||
-	die "KWStyle executable was not found.
+	KWStyle_path=$(which KWStyle)
+	if [ $? != 0 ] ; then
+		echo "KWStyle executable was not found.
+
+  No style verification will be performed with KWStyle!
 
 Please install KWStyle or set the executable location with
 
   git config hooks.KWStyle.path /path/to/KWStyle
 
-See http://public.kitware.com/KWStyle/"
-
+See http://public.kitware.com/KWStyle/
+" >&2
+		return 1
+	fi
 	KWStyle_conf=$(git config hooks.KWStyle.conf)
 	if ! test -f "$KWStyle_conf"; then
 		die "The file '$KWStyle_conf' does not exist.
@@ -201,7 +206,10 @@ run_uncrustify_on_file() {
 
 	fi # end if run uncrustify on file
 
-	if $do_KWStyle && run_style_on_file "$MERGED" KWStyle; then
+	if $do_KWStyle &&
+		$have_KWStyle &&
+		run_style_on_file "$MERGED" KWStyle
+	then
 		run_KWStyle_on_file "$MERGED"
 	else
 		return 0
@@ -210,6 +218,11 @@ run_uncrustify_on_file() {
 
 run_uncrustify() {
 	$do_KWStyle && check_for_KWStyle
+	if test $?; then
+		have_KWStyle=false
+	else
+		have_KWStyle=true
+	fi
 
 	merge_tool=$(get_merge_tool "$merge_tool") || die "Merge tool not configured.
 
@@ -245,8 +258,9 @@ elif $do_uncrustify; then
 # do_uncrustify will run KWStyle on the files incrementally so excessive
 # uncrustify merges do not have to occur.
 elif $do_KWStyle; then
-	check_for_KWStyle
-	run_KWStyle
+	if check_for_KWStyle; then
+		run_KWStyle
+	fi
 fi
 
 # vim: set filetype=sh tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab :

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c46078635786f5254f7262a580f2f16a620d78bf
commit c46078635786f5254f7262a580f2f16a620d78bf
Merge: 19f86ec d5bb076
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Mon Sep 27 16:01:05 2010 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Mon Sep 27 16:01:05 2010 -0400

    Merge branch 'style-checks' into hooks


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d5bb076453719934cd9eda65e72d337acb4fe5bd
commit d5bb076453719934cd9eda65e72d337acb4fe5bd
Author:     Matt McCormick (thewtex) <matt at mmmccormick.com>
AuthorDate: Thu Sep 9 11:45:14 2010 -0500
Commit:     Matt McCormick (thewtex) <matt at mmmccormick.com>
CommitDate: Mon Sep 27 14:53:00 2010 -0500

    pre-commit: Apply uncrustify and KWStyle check for modified files.
    
    uncrustify (uncrustify.sourceforge.net) is applied to changed files prior to
    commit.
    
    This feature is off by default.  To enable this behavior, set
    
      git config hooks.uncrustify true
    
    By default, the behavior of git-mergetool is used to review the changes
    uncrustify makes before they are added to the commit.  For more information on
    this behavior, see
    
      git help mergetool
    
    KWStyle is run on the changed C++ files and the commit is aborted if the files
    do not pass the test.  A file similar to the original is saved with a '*.kws'
    extension so that line numbers referenced in the error message can be examined.
    
    The test is off by default.  To enable this behavoir, set
    
      git config hooks.KWStyle true
    
    Project specific uncrustify and KWStyle configuration files are set with 'git
    config'.  For example,
    
      git config hooks.uncrustify.conf path/to/uncrustify.conf
      git config hooks.KWStyle.conf path/to/KWStyle.conf
      git config hooks.KWStyle.overwriteRulesConf path/to/overwrite.conf # optional
    
    If the appropriate values have not been set, die() is called.  An
    optional KWStyle overwrite rules file can also been configured.
    
    The files on which to run the style checks must also be identified in the
    repository's '.gitattributes'.  For example,
    
      *.h    hooks.style
      *.cpp  hooks.style
    
    Or, to only enable a subset of style hooks,
    
      *.h    hooks.style=KWStyle
      *.cpp  hooks.style=KWStyle,uncrustify
    
    Change-Id: Ia6b2d4136af3002eb0ec5d36f03c50df928917f4

diff --git a/pre-commit b/pre-commit
index bee9c90..15a0151 100755
--- a/pre-commit
+++ b/pre-commit
@@ -247,3 +247,9 @@ while read src_mode dst_mode src_obj dst_obj status file; do
 done
 )
 test -z "$bad" || die "$bad"
+
+#-----------------------------------------------------------------------------
+# Style hooks.
+. "$GIT_DIR/hooks/pre-commit-style"
+
+# vim: set filetype=sh tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab :
diff --git a/pre-commit-style b/pre-commit-style
new file mode 100644
index 0000000..15af958
--- /dev/null
+++ b/pre-commit-style
@@ -0,0 +1,252 @@
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#=============================================================================
+
+# Run uncrustify and KWStyle pre-commit hooks.
+#
+# 'git config' is used to enable the hooks and set their configuration files.
+# The repository .gitattributes must also enable the hooks on the targeted
+# files.
+
+do_KWStyle=$(git config --bool hooks.KWStyle) || do_KWStyle=false
+
+do_uncrustify=$(git config --bool hooks.uncrustify) || do_uncrustify=false
+
+#-----------------------------------------------------------------------------
+# Check if we want to run the style on a given file.  Uses git attributes.  If
+# the hook.style attribute is set, then all styles are executed.  If the
+# hook.style attribute is set to a value, only the values given are executed.
+# Also, do not run the style check if there are unstaged changes in the file.
+# The first positional parameter is the file to check.
+# The second positional parameter is the style to check.
+# Returns 0 for execute, 1 for don't execute.
+run_style_on_file() {
+	# Do not run on submodule changes.
+	if git diff-index --cached $against -- "$1" | grep -q '^:...... 160000'; then
+		return 1
+	fi
+	if ! git diff-files --quiet -- "$1"; then
+		# A way to always allow skipping.
+		skip_unstaged=$(git config --bool hooks.styleSkipUnstaged) ||
+		skip_unstaged=false
+		file_sha=$(git diff-index --cached --abbrev=7 $against -- "$1" | \
+		awk '{print substr($3,1,9) substr($4,1,7)}')
+		if file_skip_unstaged=$(git config "hooks.$1.styleSkipUnstaged"); then
+			if test ",$file_skip_unstaged," = ",$file_sha," -o \
+				",$file_skip_unstaged," = ",true,"; then
+				skip_unstaged=true
+			fi
+		fi
+
+		if $skip_unstaged; then
+			echo "The file '$1' contains unstaged stages.  Skipping style \
+check '$2'."
+		else
+			die "Style check '$2' cannot run on '$1' with unstaged stages.
+
+Allow skipping the style check for this commit with
+
+	git config \"hooks.$1.styleSkipUnstaged\" $file_sha"
+		fi
+		return 1
+	fi
+	style=$(git check-attr hooks.style -- "$1" |
+		  sed 's/^[^:]*: hooks.style: //')
+	case "$style" in
+		'unset')        return 1 ;;
+		'set')          return 0 ;;
+		'unspecified')  return 1 ;;
+		*)              echo ",$style," | grep -iq ",$2," && return 0 ;;
+	esac
+	return 1
+}
+
+#-----------------------------------------------------------------------------
+# KWStyle.
+check_for_KWStyle() {
+	KWStyle_path=$(git config hooks.KWStyle.path) ||
+	KWStyle_path=$(which KWStyle) ||
+	die "KWStyle executable was not found.
+
+Please install KWStyle or set the executable location with
+
+  git config hooks.KWStyle.path /path/to/KWStyle
+
+See http://public.kitware.com/KWStyle/"
+
+	KWStyle_conf=$(git config hooks.KWStyle.conf)
+	if ! test -f "$KWStyle_conf"; then
+		die "The file '$KWStyle_conf' does not exist.
+
+Please run
+
+  git config hooks.KWStyle.conf path/to/KWStyle.conf.xml"
+	fi
+	KWStyle_overWriteRulesConf=$(git config hooks.KWStyle.overwriteRulesConf)
+	if test $? -eq 0 && ! test -f "$KWStyle_overWriteRulesConf"; then
+		die "The hooks.KWStyle.overwriteRulesConf file '$KWStyle_overWriteRulesConf' does not exist."
+	fi
+}
+
+run_KWStyle_on_file() {
+	if test -z "$KWStyle_overWriteRulesConf"; then
+		"$KWStyle_path" -v -xml "$KWStyle_conf" "$1"
+	else
+		"$KWStyle_path" -v -xml "$KWStyle_conf" -o "$KWStyle_overWriteRulesConf" "$1"
+	fi
+
+	if test $? -ne 0; then
+		cp -- "$1"{,.kws}
+		die "KWStyle check failed.
+
+Line numbers in the errors shown refer to the file:
+${1}.kws"
+	fi
+}
+
+run_KWStyle() {
+	git diff-index --cached --diff-filter=ACMR --name-only $against -- |
+	while read f; do
+		if run_style_on_file "$f" KWStyle; then
+			run_KWStyle_on_file "$f"
+		fi
+	done
+}
+
+#-----------------------------------------------------------------------------
+# uncrustify.
+check_for_uncrustify() {
+	uncrustify_path=$(git config hooks.uncrustify.path) ||
+	uncrustify_path=$(which uncrustify) ||
+	die "uncrustify executable was not found.
+
+Please install uncrustify or set the executable location with
+
+  git config hooks.uncrustify.path /path/to/uncrustify
+
+  See http://uncrustify.sourceforge.net/"
+
+	uncrustify_conf=$(git config hooks.uncrustify.conf)
+	if ! test -f "$uncrustify_conf"; then
+		die "The file '$uncrustify_conf' does not exist.
+
+Please run
+
+  git config hooks.uncrustify.conf path/to/uncrustify.conf"
+	fi
+}
+
+run_uncrustify_on_file() {
+	MERGED="$1"
+	if run_style_on_file "$MERGED" uncrustify; then
+		ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')"
+		BACKUP="./$MERGED.BACKUP.$ext"
+		LOCAL="./$MERGED.STAGED.$ext"
+		REMOTE="./$MERGED.UNCRUSTIFY.$ext"
+		NEW_MERGED="./$MERGED.NEW.$ext"
+		OLD_MERGED="$MERGED"
+
+		mv -- "$MERGED" "$BACKUP"
+		# We temporarily change MERGED because the file might already be open, and
+		# the text editor may complain.
+		MERGED="$NEW_MERGED"
+		cp -- "$BACKUP" "$MERGED"
+		cp -- "$BACKUP" "$LOCAL"
+
+		if ! "$uncrustify_path" -c "$uncrustify_conf" -f "$LOCAL" \
+			-o "$REMOTE" 2> /dev/null; then
+			mv -- "$BACKUP" "$OLD_MERGED"
+
+			if test "$merge_keep_temporaries" = "false"; then
+				rm -f -- "$LOCAL" "$REMOTE" "$BACKUP"
+			fi
+
+			die "error when running uncrustify on $OLD_MERGED"
+		fi
+
+		if test $(git hash-object -- "$LOCAL") != $(git hash-object -- "$REMOTE") &&
+			! run_merge_tool "$merge_tool" "false" </dev/tty; then
+			mv -- "$BACKUP" "$OLD_MERGED"
+
+			if test "$merge_keep_temporaries" = "false"; then
+				rm -f -- "$LOCAL" "$REMOTE" "$BACKUP" "$NEW_MERGED"
+			fi
+
+			die "uncrustify merge of $OLD_MERGED failed"
+		fi
+
+		mv -- "$NEW_MERGED" "$OLD_MERGED"
+		MERGED="$OLD_MERGED"
+
+		if test "$merge_keep_backup" = "true"; then
+			mv -- "$BACKUP" "$MERGED.orig"
+		else
+			rm -- "$BACKUP"
+		fi
+
+		git add -- "$MERGED"
+		rm -f -- "$LOCAL" "$REMOTE" "$BACKUP"
+
+	fi # end if run uncrustify on file
+
+	if $do_KWStyle && run_style_on_file "$MERGED" KWStyle; then
+		run_KWStyle_on_file "$MERGED"
+	else
+		return 0
+	fi
+}
+
+run_uncrustify() {
+	$do_KWStyle && check_for_KWStyle
+
+	merge_tool=$(get_merge_tool "$merge_tool") || die "Merge tool not configured.
+
+Set the merge tool with
+
+	git config merge.tool <toolname>
+
+For more information, see
+
+	git help mergetool"
+	merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
+	merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
+	git diff-index --cached --diff-filter=ACMR --name-only $against -- |
+	while read MERGED; do
+		run_uncrustify_on_file "$MERGED"
+	done # end for changed files
+}
+
+# Do not run during merge commits for now.
+if test -f "$GIT_DIR/MERGE_HEAD"; then
+	:
+elif $do_uncrustify; then
+	# We use git-mergetool settings to review the uncrustify changes.
+	TOOL_MODE=merge
+	. "$(git --exec-path)/git-mergetool--lib"
+	# Redefine check_unchanged because we do not need to check if the merge was
+	# successful.
+	check_unchanged() {
+		status=0
+	}
+	check_for_uncrustify
+	run_uncrustify
+# do_uncrustify will run KWStyle on the files incrementally so excessive
+# uncrustify merges do not have to occur.
+elif $do_KWStyle; then
+	check_for_KWStyle
+	run_KWStyle
+fi
+
+# vim: set filetype=sh tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab :

-----------------------------------------------------------------------

Summary of changes:
 pre-commit       |    6 ++
 pre-commit-style |  266 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 272 insertions(+), 0 deletions(-)
 create mode 100644 pre-commit-style


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list