[Libreoffice-commits] .: git-hooks/pre-commit

Miklos Vajna vmiklos at kemper.freedesktop.org
Mon Aug 15 12:09:06 PDT 2011


 git-hooks/pre-commit |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

New commits:
commit 8e4adb6038f8675d87d6766e62721f8e23fc91de
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Mon Aug 15 21:05:29 2011 +0200

    git-hooks: whitespace problems are not errors in non-source files

diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
index bae5ff9..d262fe1 100755
--- a/git-hooks/pre-commit
+++ b/git-hooks/pre-commit
@@ -12,9 +12,9 @@ use Cwd;
 
 $ENV{LC_ALL} = "C";
 
-sub check_whitespaces($)
+sub check_whitespaces($$)
 {
-    my ($h) = @_;
+    my ($h, $src_exts) = @_;
 
     my $found_bad = 0;
     my $filename;
@@ -22,6 +22,7 @@ sub check_whitespaces($)
     my $lineno;
     sub bad_line {
 	my ($why, $line) = @_;
+        if ($filename =~ /\.($src_exts)$/) {
 	if (!$found_bad) {
 	    print STDERR "*\n";
 	    print STDERR "* You have some suspicious patch lines:\n";
@@ -34,6 +35,7 @@ sub check_whitespaces($)
 	}
 	print STDERR "* $why (line $lineno)\n";
 	print STDERR "$filename:$lineno:$line\n";
+        }
     }
     open( FILES, "git-diff-index -p -M --cached $h |" ) ||  die "Cannot run git diff-index.";
     while (<FILES>) {
@@ -134,12 +136,13 @@ while (my $file = <FILES>) {
 # 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 = <FILES> ) {
     chomp( $file );
     if ( $file ne "GNUmakefile" &&
-         $file =~ /\.(c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml)$/) {
+         $file =~ /\.($src_exts)$/) {
         open( F, "git diff-index -p --cached $against -- '$file' |" );
         while ( my $line = <F> ) {
             if ( $line =~ /^\+ *\t/ ) {
@@ -186,7 +189,7 @@ EOM
 }
 
 # fix whitespace in code
-check_whitespaces( $against );
+check_whitespaces( $against, $src_exts );
 
 # check the rest of the files
 my $filter_patches=`git diff-index --check --cached $against -- | sed '/\.\(diff\|patch\):/,/.*/d'`;


More information about the Libreoffice-commits mailing list