summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: edde911)
raw | patch | inline | side by side (parent: edde911)
author | Thomas Rast <trast@student.ethz.ch> | |
Tue, 26 Aug 2008 19:32:37 +0000 (21:32 +0200) | ||
committer | Eric Wong <normalperson@yhbt.net> | |
Fri, 5 Sep 2008 23:58:39 +0000 (16:58 -0700) |
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>
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>
git-svn.perl | patch | blob | history | |
t/t9119-git-svn-info.sh | patch | blob | history |
diff --git a/git-svn.perl b/git-svn.perl
index 5e61dd9c12794043a44044ac09c9fcc1c75bc606..42d0679816a2904c8fd4083fc34abb9347c0bec1 100755 (executable)
--- a/git-svn.perl
+++ b/git-svn.perl
}
}
+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);
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";
index 8709bcc49cfbc90579bd823d6dff7f050ce5d39f..181101010f999c906592d2546bbeec6b0782d841 100755 (executable)
--- a/t/t9119-git-svn-info.sh
+++ b/t/t9119-git-svn-info.sh
' "`svn info $2 | grep '^Text Last Updated:'`" "$1"
}
+quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')"
+
test_expect_success 'setup repository and import' '
mkdir info &&
cd info &&
"
test_expect_success 'info --url' '
- test "$(cd gitwc; git-svn info --url)" = "$svnrepo"
+ test "$(cd gitwc; git-svn info --url)" = "$quoted_svnrepo"
'
test_expect_success 'info .' "
"
test_expect_success 'info --url .' '
- test "$(cd gitwc; git-svn info --url .)" = "$svnrepo"
+ test "$(cd gitwc; git-svn info --url .)" = "$quoted_svnrepo"
'
test_expect_success 'info file' "
"
test_expect_success 'info --url file' '
- test "$(cd gitwc; git-svn info --url file)" = "$svnrepo/file"
+ test "$(cd gitwc; git-svn info --url file)" = "$quoted_svnrepo/file"
'
test_expect_success 'info directory' "
"
test_expect_success 'info --url directory' '
- test "$(cd gitwc; git-svn info --url directory)" = "$svnrepo/directory"
+ test "$(cd gitwc; git-svn info --url directory)" = "$quoted_svnrepo/directory"
'
test_expect_success 'info symlink-file' "
test_expect_success 'info --url symlink-file' '
test "$(cd gitwc; git-svn info --url symlink-file)" \
- = "$svnrepo/symlink-file"
+ = "$quoted_svnrepo/symlink-file"
'
test_expect_success 'info symlink-directory' "
test_expect_success 'info --url symlink-directory' '
test "$(cd gitwc; git-svn info --url symlink-directory)" \
- = "$svnrepo/symlink-directory"
+ = "$quoted_svnrepo/symlink-directory"
'
test_expect_success 'info added-file' "
test_expect_success 'info --url added-file' '
test "$(cd gitwc; git-svn info --url added-file)" \
- = "$svnrepo/added-file"
+ = "$quoted_svnrepo/added-file"
'
test_expect_success 'info added-directory' "
test_expect_success 'info --url added-directory' '
test "$(cd gitwc; git-svn info --url added-directory)" \
- = "$svnrepo/added-directory"
+ = "$quoted_svnrepo/added-directory"
'
test_expect_success 'info added-symlink-file' "
test_expect_success 'info --url added-symlink-file' '
test "$(cd gitwc; git-svn info --url added-symlink-file)" \
- = "$svnrepo/added-symlink-file"
+ = "$quoted_svnrepo/added-symlink-file"
'
test_expect_success 'info added-symlink-directory' "
test_expect_success 'info --url added-symlink-directory' '
test "$(cd gitwc; git-svn info --url added-symlink-directory)" \
- = "$svnrepo/added-symlink-directory"
+ = "$quoted_svnrepo/added-symlink-directory"
'
# The next few tests replace the "Text Last Updated" value with a
test_expect_success 'info --url file (deleted)' '
test "$(cd gitwc; git-svn info --url file)" \
- = "$svnrepo/file"
+ = "$quoted_svnrepo/file"
'
test_expect_success 'info deleted-directory' "
test_expect_success 'info --url directory (deleted)' '
test "$(cd gitwc; git-svn info --url directory)" \
- = "$svnrepo/directory"
+ = "$quoted_svnrepo/directory"
'
test_expect_success 'info deleted-symlink-file' "
test_expect_success 'info --url symlink-file (deleted)' '
test "$(cd gitwc; git-svn info --url symlink-file)" \
- = "$svnrepo/symlink-file"
+ = "$quoted_svnrepo/symlink-file"
'
test_expect_success 'info deleted-symlink-directory' "
test_expect_success 'info --url symlink-directory (deleted)' '
test "$(cd gitwc; git-svn info --url symlink-directory)" \
- = "$svnrepo/symlink-directory"
+ = "$quoted_svnrepo/symlink-directory"
'
# NOTE: git does not have the concept of replaced objects,