From 262b5931c8975e90037f635d7b2ecfd198a0803a Mon Sep 17 00:00:00 2001 From: Norbert Thiebaud Date: Tue, 16 Aug 2011 00:37:26 -0500 Subject: put git hook on a diet. concentrate on safe, cheap and globally useful --- git-hooks/pre-commit | 125 +++++++++++++-------------------------------------- 1 file changed, 32 insertions(+), 93 deletions(-) (limited to 'git-hooks') diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit index d262fe108916..cdf6e44eaf91 100755 --- a/git-hooks/pre-commit +++ b/git-hooks/pre-commit @@ -6,23 +6,24 @@ # if it wants to stop the commit. use strict; -use File::Temp qw/ :mktemp /; -use File::Copy; -use Cwd; +#use File::Copy; +#use Cwd; $ENV{LC_ALL} = "C"; -sub check_whitespaces($$) +sub check_whitespaces($) { - my ($h, $src_exts) = @_; + my ($h) = @_; + my $src_limited = "c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml"; + my $src_full = "c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|mk|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml"; my $found_bad = 0; my $filename; my $reported_filename = ""; my $lineno; sub bad_line { - my ($why, $line) = @_; - if ($filename =~ /\.($src_exts)$/) { + my ($why, $line, $file_filter) = @_; + if (!defined $file_filter || $filename =~ /\.($file_filter)$/) { if (!$found_bad) { print STDERR "*\n"; print STDERR "* You have some suspicious patch lines:\n"; @@ -55,13 +56,13 @@ sub check_whitespaces($$) $lineno++; chomp; if (/\s$/) { - bad_line("trailing whitespace", $_); + bad_line("trailing whitespace", $_ , $src_limited); } if (/^\s* /) { - bad_line("indent SP followed by a TAB", $_); + bad_line("indent SP followed by a TAB", $_, $src_limited); } - if (/^(?:[<>=]){7}/) { - bad_line("unresolved merge conflict", $_); + if (/^(?:[<>=]){7}$/) { + bad_line("unresolved merge conflict", $src_full); } } } @@ -93,35 +94,35 @@ if ( $allownonascii ne "true" && LC_ALL=C tr -d '[ -~]\\0'` ne "" ) { print <) { - chomp($file); - if ($file =~ /\.hxx$/) { - system("$doxycheck -q $file | sed 's|".getcwd()."/||;'"); - } -} +#my $doxycheck = "../../bin/find-undocumented-classes"; +#if (! -e $doxycheck) { +# # bootstrap repo +# $doxycheck =~ s|../../||; +#} +#open(FILES, "git diff-index --cached --name-only --diff-filter=A $against |") || die "Cannot run git diff-index."; +#while (my $file = ) { +# chomp($file); +# if ($file =~ /\.hxx$/) { +# system("$doxycheck -q $file | sed 's|".getcwd()."/||;'"); +# } +#} # run 'msgcat --nowrap' when committing *.po files open(FILES, "git diff-index --cached --name-only $against |") || die "Cannot run git diff-index."; @@ -133,70 +134,8 @@ while (my $file = ) { } } -# be strict about tabs - we don't want them at all, setup your editor -# correctly ;-) -my $err_ext = ""; -my $src_exts = "c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml"; - -open( FILES, "git diff-index --cached --name-only $against |" ) || die "Cannot run git diff-index."; -while ( my $file = ) { - chomp( $file ); - if ( $file ne "GNUmakefile" && - $file =~ /\.($src_exts)$/) { - open( F, "git diff-index -p --cached $against -- '$file' |" ); - while ( my $line = ) { - if ( $line =~ /^\+ *\t/ ) { - $err_ext .= "$file\n"; - last; - } - } - } - close( F ); -} -close( FILES ); - -if ( $err_ext ne "" ) { - print <