git-svn: eol_cp corner-case fixes
If we read the maximum size of our buffer into $buf, and the last character is '\015', there's a chance that the character is '\012', which means our regex won't work correctly. At the worst case, this could introduce an extra newline into the code. We'll now read an extra character if we see '\015' is the last character in $buf. We also forgot to recalculate the length of $buf after doing the newline substitution, causing some files to appeare truncated. We'll do that now and force byte semantics in length() for good measure. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jun 9, 2006 at 23:27 UTC
4a393f2b53f0997f79d47793d4c774fa0072887c
1 file changed
+11
-4
contrib/git-svn/git-svn.perl
+11
-4
@@ -866,19 +866,26 @@ sub eol_cp {
866
binmode $wfd or croak $!;
867
868
my $eol = $EOL{$es} or undef;
869
- if ($eol) {
870
- print "$eol: $from => $to\n";
871
- }
869
my $buf;
870
+ use bytes;
871
while (1) {
872
my ($r, $w, $t);
873
defined($r = sysread($rfd, $buf, 4096)) or croak $!;
874
return unless $r;
877
- $buf =~ s/(?:\015|\012|\015\012)/$eol/gs if $eol;
875
+ if ($eol) {
876
+ if ($buf =~ /\015$/) {
877
+ my $c;
878
+ defined($r = sysread($rfd,$c,1)) or croak $!;
879
+ $buf .= $c if $r > 0;
880
+ }
881
+ $buf =~ s/(?:\015\012|\015|\012)/$eol/gs;
882
+ $r = length($buf);
883
+ }
884
for ($w = 0; $w < $r; $w += $t) {
885
$t = syswrite($wfd, $buf, $r - $w, $w) or croak $!;
886
}
887
}
888
+ no bytes;
889
}
890
891
sub do_update_index {