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

[PATCH] git-svn: handle leading/trailing whitespace from svnsync revprops

From
EWEric Wong <normalperson@yhbt.net>
Date
Jan 12, 2008, 07:13 UTC
Message-ID
<20080112071355.GA17021@soma>
In-Reply-To
<7vmyrd5p81.fsf@gitster.siamese.dyndns.org>

Repositories generated by svnsync cannot be relied on to have properly set revprops without newlines in UUIDs and URLs. There may be broken versions of svnsync out there that append extra newlines to UUIDs, or the revprops could've been changed by repository administrators at any time, too.

At least one repository we've come across has an embedded newline erroneously set in the svnsync-uuid prop. This is bad because the trailing newline is taken as another record by the Git.pm library, and the wantarray detection causes tmp_config() to return an array with an empty-but-existing second element.

We will now strip leading and trailing whitespace both before setting and after reading the uuid and url for svnsync values. We will also force tmp_config to return a single scalar when reading existing values.

SVN UUIDs should never have whitespace in them, and SVN repository URLs should be URI-escaped, so neither of those values we ever see in git-svn should actually have whitespace in them.

Thanks to Dennis Schridde for the bug report and Junio for helping diagnose this.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
 git-svn.perl |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 3308fe1..f40ad2c 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -1758,10 +1758,16 @@ sub svnsync {
 	# see if we have it in our config, first:
 	eval {
 		my $section = "svn-remote.$self->{repo_id}";
-		$svnsync = {
-		  url => tmp_config('--get', "$section.svnsync-url"),
-		  uuid => tmp_config('--get', "$section.svnsync-uuid"),
-		}
+
+	        my $url = tmp_config('--get', "$section.svnsync-url");
+		($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
+	           die "doesn't look right - svn:sync-from-url is '$url'\n";
+
+	        my $uuid = tmp_config('--get', "$section.svnsync-uuid");
+		($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or
+	           die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
+
+		$svnsync = { url => $url, uuid => $uuid }
 	};
 	if ($svnsync && $svnsync->{url} && $svnsync->{uuid}) {
 		return $self->{svnsync} = $svnsync;
@@ -1772,11 +1778,11 @@ sub svnsync {
 	my $rp = $self->ra->rev_proplist(0);
 
 	my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
-	$url =~ m{^[a-z\+]+://} or
+	($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
 	           die "doesn't look right - svn:sync-from-url is '$url'\n";
 
 	my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
-	$uuid =~ m{^[0-9a-f\-]{30,}$} or
+	($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or
 	           die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
 
 	my $section = "svn-remote.$self->{repo_id}";
-- 
Eric Wong
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 18 in “Odd number of elements in anonymous hash”
  1. Dennis SchriddeJan 8, 2008
  2. Junio C HamanoJan 8, 2008
  3. Dennis SchriddeJan 8, 2008
  4. Eric WongJan 10, 2008
  5. Dennis SchriddeJan 10, 2008
  6. Dennis SchriddeJan 10, 2008
  7. Junio C HamanoJan 10, 2008
  8. Dennis SchriddeJan 10, 2008
  9. Junio C HamanoJan 10, 2008
  10. git-svn: handle leading/trailing whitespace from svnsync revpropsEric Wong, Jan 12, 2008
  11. Junio C HamanoJan 12, 2008
  12. Eric WongJan 12, 2008
  13. Björn SteinbrinkJan 12, 2008
  14. Junio C HamanoJan 12, 2008
  15. Junio C HamanoJan 12, 2008
  16. Dennis SchriddeJan 12, 2008
  17. Eric WongJan 9, 2008
  18. Sam VilainJan 24, 2008

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.