From: Thomas Rast <trast@student.ethz.ch>
To: git@vger.kernel.org
Cc: Eric Wong <normalperson@yhbt.net>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 6/6] git svn info: always quote URLs in 'info' output
Date: Tue, 26 Aug 2008 21:32:37 +0200 [thread overview]
Message-ID: <1219779157-31602-7-git-send-email-trast@student.ethz.ch> (raw)
In-Reply-To: <1219779157-31602-6-git-send-email-trast@student.ethz.ch>
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>
---
I wasn't sure if I should quote --url too. It is not an 'svn info'
feature, so we could do it either way. Eventually I decided for the
change to be consistent with the 'URL:' field of normal output. If
this breaks scripts for someone, I can change it back.
git-svn.perl | 25 ++++++++++++++++++++++---
t/t9119-git-svn-info.sh | 30 ++++++++++++++++--------------
2 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 46bc0b0..11ff813 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";
diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh
index 8709bcc..1811010 100755
--- a/t/t9119-git-svn-info.sh
+++ b/t/t9119-git-svn-info.sh
@@ -34,6 +34,8 @@ ptouch() {
' "`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 &&
@@ -70,7 +72,7 @@ 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 .' "
@@ -80,7 +82,7 @@ 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' "
@@ -90,7 +92,7 @@ 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' "
@@ -106,7 +108,7 @@ test_expect_success 'info inside 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' "
@@ -117,7 +119,7 @@ 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' "
@@ -130,7 +132,7 @@ 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' "
@@ -150,7 +152,7 @@ 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' "
@@ -172,7 +174,7 @@ 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' "
@@ -195,7 +197,7 @@ 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' "
@@ -218,7 +220,7 @@ 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
@@ -244,7 +246,7 @@ test_expect_success 'info deleted-file' "
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' "
@@ -265,7 +267,7 @@ 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' "
@@ -287,7 +289,7 @@ 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' "
@@ -309,7 +311,7 @@ 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,
--
1.6.0.1.96.g9307e.dirty
next prev parent reply other threads:[~2008-08-26 19:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-26 19:32 [PATCH 0/6] 'git svn info' fixes Thomas Rast
2008-08-26 19:32 ` [PATCH 1/6] git svn info: tests: let 'init' test run with SVN 1.5 Thomas Rast
2008-08-26 19:32 ` [PATCH 2/6] git svn info: tests: do not use set -e Thomas Rast
2008-08-26 19:32 ` [PATCH 3/6] git svn info: tests: use test_cmp instead of git-diff Thomas Rast
2008-08-26 19:32 ` [PATCH 4/6] git svn info: tests: fix ptouch argument order in setup Thomas Rast
2008-08-26 19:32 ` [PATCH 5/6] git svn info: make info relative to the current directory Thomas Rast
2008-08-26 19:32 ` Thomas Rast [this message]
2008-08-27 9:43 ` [PATCH 6/6] git svn info: always quote URLs in 'info' output Eric Wong
2008-08-27 9:53 ` [PATCH 0/6] 'git svn info' fixes Eric Wong
2008-08-28 8:30 ` Thomas Rast
2008-08-29 8:16 ` Eric Wong
2008-08-29 13:42 ` [PATCH 0/2] *** SUBJECT HERE *** Thomas Rast
2008-08-29 13:42 ` [PATCH 1/2] git-svn: match SVN 1.5 behaviour of info' on unknown item Thomas Rast
2008-08-29 13:42 ` [PATCH 2/2] git-svn: fix 'info' tests for unknown items Thomas Rast
2008-08-30 1:03 ` [PATCH 0/2] 'git svn info' fixes Eric Wong
2008-09-01 9:46 ` Thomas Rast
2008-09-01 22:58 ` Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1219779157-31602-7-git-send-email-trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=normalperson@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).