From: Eric Wong Date: Sat, 10 Jun 2006 06:27:01 +0000 (-0700) Subject: git-svn: eol_cp corner-case fixes X-Git-Tag: v1.4.1-rc1~26^2~17^2~22 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4a393f2b53f0997f79d47793d4c774fa0072887c;p=git.git 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 --- diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl index 7ed11ef0a..8d2e7f74e 100755 --- a/contrib/git-svn/git-svn.perl +++ b/contrib/git-svn/git-svn.perl @@ -866,19 +866,26 @@ sub eol_cp { binmode $wfd or croak $!; my $eol = $EOL{$es} or undef; - if ($eol) { - print "$eol: $from => $to\n"; - } my $buf; + use bytes; while (1) { my ($r, $w, $t); defined($r = sysread($rfd, $buf, 4096)) or croak $!; return unless $r; - $buf =~ s/(?:\015|\012|\015\012)/$eol/gs if $eol; + if ($eol) { + if ($buf =~ /\015$/) { + my $c; + defined($r = sysread($rfd,$c,1)) or croak $!; + $buf .= $c if $r > 0; + } + $buf =~ s/(?:\015\012|\015|\012)/$eol/gs; + $r = length($buf); + } for ($w = 0; $w < $r; $w += $t) { $t = syswrite($wfd, $buf, $r - $w, $w) or croak $!; } } + no bytes; } sub do_update_index {