git svn info: always quote URLs in 'info' output
Changes 'git svn info' to always URL-escape the 'URL' and 'Repository' fields and --url output, like SVN (at least 1.5) does. Note that reusing the escape_url() further down in Git::SVN::Ra is not possible because it only triggers for http(s) URLs. I did not know whether extending it to all schemes would break SVN access anywhere, so I made a new one that quotes in all schemes. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Acked-by: Eric Wong <normalperson@yhbt.net>
This commit is contained in:
25
git-svn.perl
25
git-svn.perl
@ -803,6 +803,25 @@ sub cmd_commit_diff {
|
||||
}
|
||||
}
|
||||
|
||||
sub escape_uri_only {
|
||||
my ($uri) = @_;
|
||||
my @tmp;
|
||||
foreach (split m{/}, $uri) {
|
||||
s/([^\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
|
||||
push @tmp, $_;
|
||||
}
|
||||
join('/', @tmp);
|
||||
}
|
||||
|
||||
sub escape_url {
|
||||
my ($url) = @_;
|
||||
if ($url =~ m#^([^:]+)://([^/]*)(.*)$#) {
|
||||
my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only($3));
|
||||
$url = "$scheme://$domain$uri";
|
||||
}
|
||||
$url;
|
||||
}
|
||||
|
||||
sub cmd_info {
|
||||
my $path = canonicalize_path(defined($_[0]) ? $_[0] : ".");
|
||||
my $fullpath = canonicalize_path($cmd_dir_prefix . $path);
|
||||
@ -829,18 +848,18 @@ sub cmd_info {
|
||||
my $full_url = $url . ($fullpath eq "" ? "" : "/$fullpath");
|
||||
|
||||
if ($_url) {
|
||||
print $full_url, "\n";
|
||||
print escape_url($full_url), "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
my $result = "Path: $path\n";
|
||||
$result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
|
||||
$result .= "URL: " . $full_url . "\n";
|
||||
$result .= "URL: " . escape_url($full_url) . "\n";
|
||||
|
||||
eval {
|
||||
my $repos_root = $gs->repos_root;
|
||||
Git::SVN::remove_username($repos_root);
|
||||
$result .= "Repository Root: $repos_root\n";
|
||||
$result .= "Repository Root: " . escape_url($repos_root) . "\n";
|
||||
};
|
||||
if ($@) {
|
||||
$result .= "Repository Root: (offline)\n";
|
||||
|
Reference in New Issue
Block a user