diff options
author | Thomas Rast <trast@student.ethz.ch> | 2008-08-26 21:32:37 +0200 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-09-05 16:58:39 -0700 |
commit | 05427b91f0b5e45688cbea21faf0f2d79ec07b21 (patch) | |
tree | 7951ab6f2dbdc5d888b2ec7330230203bcfb6d14 /git-svn.perl | |
parent | edde9112abd1ef5f4565468e8a9a500e0c03f900 (diff) | |
download | git-05427b91f0b5e45688cbea21faf0f2d79ec07b21.tar.gz |
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>
Diffstat (limited to 'git-svn.perl')
-rwxr-xr-x | git-svn.perl | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/git-svn.perl b/git-svn.perl index 5e61dd9c12..42d0679816 100755 --- a/git-svn.perl +++ b/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"; |