@matheusbsbs / matheus-bagliano / commits / 98fa5b6851
Fork 0

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

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Wong committed Jan 11, 2008 at 23:13 UTC 98fa5b68512b9d02d8d47e726bfaec4d33598246
1 file changed +12 -6
git-svn.perl
+12 -6
@@ -1758,10 +1758,16 @@ sub svnsync {
1758 # see if we have it in our config, first:
1759 eval {
1760 my $section = "svn-remote.$self->{repo_id}";
1761 - $svnsync = {
1762 - url => tmp_config('--get', "$section.svnsync-url"),
1763 - uuid => tmp_config('--get', "$section.svnsync-uuid"),
1764 - }
1761 +
1762 + my $url = tmp_config('--get', "$section.svnsync-url");
1763 + ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
1764 + die "doesn't look right - svn:sync-from-url is '$url'\n";
1765 +
1766 + my $uuid = tmp_config('--get', "$section.svnsync-uuid");
1767 + ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or
1768 + die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
1769 +
1770 + $svnsync = { url => $url, uuid => $uuid }
1771 };
1772 if ($svnsync && $svnsync->{url} && $svnsync->{uuid}) {
1773 return $self->{svnsync} = $svnsync;
@@ -1772,11 +1778,11 @@ sub svnsync {
1778 my $rp = $self->ra->rev_proplist(0);
1779
1780 my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
1775 - $url =~ m{^[a-z\+]+://} or
1781 + ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
1782 die "doesn't look right - svn:sync-from-url is '$url'\n";
1783
1784 my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
1779 - $uuid =~ m{^[0-9a-f\-]{30,}$} or
1785 + ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or
1786 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
1787
1788 my $section = "svn-remote.$self->{repo_id}";