Hi all,
This is my first easy hack. I made change in the function
check_and_fix_whitespace() the filter all the files that don't match the
list given in the wiki (c, cpp, cxx, h, hrc, hxx, idl, in, java, map, mk,
MK, pmk, pl, pm, sdi, sh, src, tab, xcu, xml)
This patches is release under the LGPLv3+/MPL.
Cheers
Maxime
From abad7922b457fb3c7b27b969944f9c3cc1b51753 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maxime=20C=C3=B4t=C3=A9?=
Date: Mon, 18 Apr 2011 21:39:50 -0400
Subject: [PATCH] Easy hack Improve git pre-commit hook
Change of the function check_and_fix_whitespace() to check only file with the extension listed (c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|mk|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml)
---
git-hooks/pre-commit | 55 +
1 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
index 6817990..6c6fe4e 100755
--- a/git-hooks/pre-commit
+++ b/git-hooks/pre-commit
@@ -18,11 +18,6 @@ $ENV{LC_ALL} = "C";
sub fix_whitespace($$) {
my ( $file, $lines ) = @_;
-# usually we have nothing to do ;-)
-return if ( keys( %{$lines} ) == 0 ||
-$file eq "" || $file eq "GNUmakefile" ||
-!( $file =~ /\.(c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pl|pm|pmk|py|sdi|sh|src|tab)/ ) );
-
open( IN, "$file" ) || die "Cannot open $file for reading";
my ( $out, $tmpfile ) = mkstemp( "/tmp/whitespace-fixing-XX" );
@@ -66,36 +61,42 @@ sub check_and_fix_whitespace($)
my $fd;
( $fd, $stash ) = mkstemp( "/tmp/unstaged-changes-XX" );
close( $fd );
+
# this will keep the staged changes
system( "git diff > $stash" );
system( "git checkout ." );
}
-open( IN, "git diff-index -p --no-prefix --cached $head -- |" ) || die "Cannot get git diff-index";
-while ( my $line = ) {
-if ( $line =~ /^\+\+\+ (.*)/ ) {
+open( FILES, "git diff-index --cached --name-only $head |" ) || die "Cannot run git diff-index.";
+while( my $file = ) {
+chomp( $file );
+if ( $file ne "GNUmakefile" &&
+ ( $file =~ /\.(c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pl|pm|pmk|py|sdi|sh|src|tab)/ ) ) {
+open( F, "git diff-index -p --cached $head -- $file |" );
+while ( my $line = ) {
+if ( $line =~ /^\+\+\+ (.*)/ ) {
+%lines = ();
+$line_no = 0;
+$line_max = -1;
+}
+elsif ( $line =~ /^@@ -[0-9]+,[0-9]+ \+([0-9]+),([0-9]+) @@/ ) {
+$line_no = $1;
+$line_max = $line_no + $2;
+}
+elsif ( ( $line_no < $line_max ) && ( $line =~ /^[ +]/ ) ) {
+if ( $line =~ /^\+.*[ \t]$/ ) {
+$lines{$line_no} = 1;
+}
+++$line_no;
+}
+}
fix_whitespace( $file, \%lines );
-$file = $1;
-%lines = ();
-$line_no = 0;
-$line_max = -1;
-}
-elsif ( $line =~ /^@@ -[0-9]+,[0-9]+ \+([0-9]+),([0-9]+) @@/ ) {
-$line_no = $1;
-$line_max = $line_no + $2;
-}
-elsif ( ( $line_no < $line_max ) && ( $line =~ /^[ +]/ ) ) {
-if ( $line =~ /^\+.*[ \t]$/ ) {
-$lines{$line_no} = 1;
+close( IN );
+if ($stash) {
+system( "git apply < $stash" );
+unlink( $stash );
}
-++$line_no;
}
}
-fix_whitespace( $file, \%lines );
-close( IN );
-if ($stash) {
-system( "git apply < $stash" );
-unlink( $stash );
-}
}
# Do the work :-)
--
1.7.4.4
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice