Created
May 27, 2010 15:45
-
-
Save miau/415963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
use strict; | |
use warnings; | |
# git status -s | grep modified: | awk '{ print $3;}' > changed_files.txt | |
my $infile = 'changed_files.txt'; | |
open my $in, '<', $infile or die "can't open $infile: $!"; | |
my @files = <$in>; | |
close $in; | |
foreach my $file (@files) { | |
chomp $file; | |
my $line_count = (split(/\s/, `wc -l $file`))[0]; | |
my $diff = `git diff $file`; | |
$diff =~ s/^([-+])\1+//mg; | |
my $plus = ($diff =~ s/^\+//mg); | |
my $minus = ($diff =~ s/^-//mg); | |
#print "$file $line_count $plus $minus\n"; | |
next if $line_count != $plus || $plus != $minus; | |
print "$file\n"; | |
system "perl -i -pe's/\\n/\\r\\n/' $file"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git diff したら変更ファイルの改行コードが CRLF が LF に変わってたから、その改行コードを CRLF に戻すのに使ったスクリプト。
改行コードが変わっていたファイルは grep で全置換を行っていたファイルで、行数=変更行数である可能性が高いことから、wc -l の結果と + や - で始まる行の行数が同じなら改行コードが変わってしまったとみなして、LF を CRLF に変換する。