[Libreoffice-commits] .: git-hooks/pre-commit
David Tardon
dtardon at kemper.freedesktop.org
Tue May 17 05:23:33 PDT 2011
git-hooks/pre-commit | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
New commits:
commit c15f51baeba2485a35254be2b4dcfff7bc81a482
Author: David Tardon <dtardon at redhat.com>
Date: Tue May 17 13:15:03 2011 +0200
do not overwrite file if no whitespace was stripped
diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
index 8a316fd..f71ad6f 100755
--- a/git-hooks/pre-commit
+++ b/git-hooks/pre-commit
@@ -21,12 +21,15 @@ sub fix_whitespace($$) {
open( IN, "$file" ) || die "Cannot open $file for reading";
my ( $out, $tmpfile ) = mkstemp( "/tmp/whitespace-fixing-XXXXXX" );
+ my $changed = 0;
my $line_no = 1;
while ( my $line = <IN> ) {
if ( $lines->{$line_no} && $line =~ /^(.*[^ \t])[ \t]+$/ ) {
+ $changed = 1;
print $out "$1\n";
}
elsif ( $lines->{$line_no} && $line =~ /^[ \t]+$/ ) {
+ $changed = 1;
print $out "\n";
}
else {
@@ -37,10 +40,13 @@ sub fix_whitespace($$) {
close( $out );
close( IN );
- move( $tmpfile, $file ) or die "Cannot move '$tmpfile' to '$file'";
+ if ( $changed )
+ {
+ move( $tmpfile, $file ) or die "Cannot move '$tmpfile' to '$file'";
- system( "git add $file" );
- print "Fixed whitespace in '$file'\n";
+ system( "git add $file" );
+ print "Fixed whitespace in '$file'\n";
+ }
}
# go through the patch and collect lines to fix
More information about the Libreoffice-commits
mailing list