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>
Thomas Rast committed
Aug 26, 2008 at 21:32 UTC
05427b91f0b5e45688cbea21faf0f2d79ec07b21
2 files changed
+38
-17
git-svn.perl
+22
-3
@@ -803,6 +803,25 @@ sub cmd_commit_diff {
803
}
804
}
805
806
+sub escape_uri_only {
807
+ my ($uri) = @_;
808
+ my @tmp;
809
+ foreach (split m{/}, $uri) {
810
+ s/([^\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
811
+ push @tmp, $_;
812
+ }
813
+ join('/', @tmp);
814
+}
815
+
816
+sub escape_url {
817
+ my ($url) = @_;
818
+ if ($url =~ m#^([^:]+)://([^/]*)(.*)$#) {
819
+ my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only($3));
820
+ $url = "$scheme://$domain$uri";
821
+ }
822
+ $url;
823
+}
824
+
825
sub cmd_info {
826
my $path = canonicalize_path(defined($_[0]) ? $_[0] : ".");
827
my $fullpath = canonicalize_path($cmd_dir_prefix . $path);
@@ -829,18 +848,18 @@ sub cmd_info {
848
my $full_url = $url . ($fullpath eq "" ? "" : "/$fullpath");
849
850
if ($_url) {
832
- print $full_url, "\n";
851
+ print escape_url($full_url), "\n";
852
return;
853
}
854
855
my $result = "Path: $path\n";
856
$result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
838
- $result .= "URL: " . $full_url . "\n";
857
+ $result .= "URL: " . escape_url($full_url) . "\n";
858
859
eval {
860
my $repos_root = $gs->repos_root;
861
Git::SVN::remove_username($repos_root);
843
- $result .= "Repository Root: $repos_root\n";
862
+ $result .= "Repository Root: " . escape_url($repos_root) . "\n";
863
};
864
if ($@) {
865
$result .= "Repository Root: (offline)\n";
t/t9119-git-svn-info.sh
+16
-14
@@ -34,6 +34,8 @@ ptouch() {
34
' "`svn info $2 | grep '^Text Last Updated:'`" "$1"
35
}
36
37
+quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')"
38
+
39
test_expect_success 'setup repository and import' '
40
mkdir info &&
41
cd info &&
@@ -70,7 +72,7 @@ test_expect_success 'info' "
72
"
73
74
test_expect_success 'info --url' '
73
- test "$(cd gitwc; git-svn info --url)" = "$svnrepo"
75
+ test "$(cd gitwc; git-svn info --url)" = "$quoted_svnrepo"
76
'
77
78
test_expect_success 'info .' "
@@ -80,7 +82,7 @@ test_expect_success 'info .' "
82
"
83
84
test_expect_success 'info --url .' '
83
- test "$(cd gitwc; git-svn info --url .)" = "$svnrepo"
85
+ test "$(cd gitwc; git-svn info --url .)" = "$quoted_svnrepo"
86
'
87
88
test_expect_success 'info file' "
@@ -90,7 +92,7 @@ test_expect_success 'info file' "
92
"
93
94
test_expect_success 'info --url file' '
93
- test "$(cd gitwc; git-svn info --url file)" = "$svnrepo/file"
95
+ test "$(cd gitwc; git-svn info --url file)" = "$quoted_svnrepo/file"
96
'
97
98
test_expect_success 'info directory' "
@@ -106,7 +108,7 @@ test_expect_success 'info inside directory' "
108
"
109
110
test_expect_success 'info --url directory' '
109
- test "$(cd gitwc; git-svn info --url directory)" = "$svnrepo/directory"
111
+ test "$(cd gitwc; git-svn info --url directory)" = "$quoted_svnrepo/directory"
112
'
113
114
test_expect_success 'info symlink-file' "
@@ -117,7 +119,7 @@ test_expect_success 'info symlink-file' "
119
120
test_expect_success 'info --url symlink-file' '
121
test "$(cd gitwc; git-svn info --url symlink-file)" \
120
- = "$svnrepo/symlink-file"
122
+ = "$quoted_svnrepo/symlink-file"
123
'
124
125
test_expect_success 'info symlink-directory' "
@@ -130,7 +132,7 @@ test_expect_success 'info symlink-directory' "
132
133
test_expect_success 'info --url symlink-directory' '
134
test "$(cd gitwc; git-svn info --url symlink-directory)" \
133
- = "$svnrepo/symlink-directory"
135
+ = "$quoted_svnrepo/symlink-directory"
136
'
137
138
test_expect_success 'info added-file' "
@@ -150,7 +152,7 @@ test_expect_success 'info added-file' "
152
153
test_expect_success 'info --url added-file' '
154
test "$(cd gitwc; git-svn info --url added-file)" \
153
- = "$svnrepo/added-file"
155
+ = "$quoted_svnrepo/added-file"
156
'
157
158
test_expect_success 'info added-directory' "
@@ -172,7 +174,7 @@ test_expect_success 'info added-directory' "
174
175
test_expect_success 'info --url added-directory' '
176
test "$(cd gitwc; git-svn info --url added-directory)" \
175
- = "$svnrepo/added-directory"
177
+ = "$quoted_svnrepo/added-directory"
178
'
179
180
test_expect_success 'info added-symlink-file' "
@@ -195,7 +197,7 @@ test_expect_success 'info added-symlink-file' "
197
198
test_expect_success 'info --url added-symlink-file' '
199
test "$(cd gitwc; git-svn info --url added-symlink-file)" \
198
- = "$svnrepo/added-symlink-file"
200
+ = "$quoted_svnrepo/added-symlink-file"
201
'
202
203
test_expect_success 'info added-symlink-directory' "
@@ -218,7 +220,7 @@ test_expect_success 'info added-symlink-directory' "
220
221
test_expect_success 'info --url added-symlink-directory' '
222
test "$(cd gitwc; git-svn info --url added-symlink-directory)" \
221
- = "$svnrepo/added-symlink-directory"
223
+ = "$quoted_svnrepo/added-symlink-directory"
224
'
225
226
# The next few tests replace the "Text Last Updated" value with a
@@ -244,7 +246,7 @@ test_expect_success 'info deleted-file' "
246
247
test_expect_success 'info --url file (deleted)' '
248
test "$(cd gitwc; git-svn info --url file)" \
247
- = "$svnrepo/file"
249
+ = "$quoted_svnrepo/file"
250
'
251
252
test_expect_success 'info deleted-directory' "
@@ -265,7 +267,7 @@ test_expect_success 'info deleted-directory' "
267
268
test_expect_success 'info --url directory (deleted)' '
269
test "$(cd gitwc; git-svn info --url directory)" \
268
- = "$svnrepo/directory"
270
+ = "$quoted_svnrepo/directory"
271
'
272
273
test_expect_success 'info deleted-symlink-file' "
@@ -287,7 +289,7 @@ test_expect_success 'info deleted-symlink-file' "
289
290
test_expect_success 'info --url symlink-file (deleted)' '
291
test "$(cd gitwc; git-svn info --url symlink-file)" \
290
- = "$svnrepo/symlink-file"
292
+ = "$quoted_svnrepo/symlink-file"
293
'
294
295
test_expect_success 'info deleted-symlink-directory' "
@@ -309,7 +311,7 @@ test_expect_success 'info deleted-symlink-directory' "
311
312
test_expect_success 'info --url symlink-directory (deleted)' '
313
test "$(cd gitwc; git-svn info --url symlink-directory)" \
312
- = "$svnrepo/symlink-directory"
314
+ = "$quoted_svnrepo/symlink-directory"
315
'
316
317
# NOTE: git does not have the concept of replaced objects,