git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] git-svn: eol_cp corner-case fixes

From
EWEric Wong <normalperson@yhbt.net>
Date
Jun 11, 2006, 07:03 UTC
Message-ID
<11500094292561-git-send-email-normalperson@yhbt.net>
In-Reply-To
<11500094281515-git-send-email-normalperson@yhbt.net>

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>
---
 contrib/git-svn/git-svn.perl |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl
index 7ed11ef..8d2e7f7 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 {
-- 
1.3.3.g2dc7b-dirty
Previous: Eric WongNext: Eric Wong
Message 4 of 6 in “git-svn: bug fixes (some resends)”
  1. git-svn: bug fixes (some resends)Eric Wong, Jun 11, 2006
  2. 1/5 git-svn: t0000: add -f flag to checkoutEric Wong, Jun 11, 2006
  3. 2/5 git-svn: fix handling of filenames with embedded '@'Eric Wong, Jun 11, 2006
  4. 3/5 git-svn: eol_cp corner-case fixesEric Wong, Jun 11, 2006
  5. 4/5 git-svn: restore original LC_ALL setting (or unset) for commitEric Wong, Jun 11, 2006
  6. 5/5 git-svn: don't allow commit if svn tree is not currentEric Wong, Jun 11, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.