git-svn: support for funky branch and project names over HTTP(S)
SVN requires that paths be URI-escaped for HTTP(S) repositories. file:// and svn:// repositories do not need these rules. Additionally, accessing individual paths inside repositories (check_path() and get_log() do NOT require escapes to function and in fact it breaks things). Noticed-by: Michael J. Cohen <mjc@cruiseplanners.com> Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Wong committed
Nov 11, 2007 at 23:37 UTC
cfbe7ab333d68790eb37341e30f040f99cef6af7
2 files changed
+62
-2
git-svn.perl
+22
-2
@@ -3223,6 +3223,25 @@ sub _auth_providers () {
3223
]
3224
}
3225
3226
+sub escape_uri_only {
3227
+ my ($uri) = @_;
3228
+ my @tmp;
3229
+ foreach (split m{/}, $uri) {
3230
+ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg;
3231
+ push @tmp, $_;
3232
+ }
3233
+ join('/', @tmp);
3234
+}
3235
+
3236
+sub escape_url {
3237
+ my ($url) = @_;
3238
+ if ($url =~ m#^(https?)://([^/]+)(.*)$#) {
3239
+ my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only($3));
3240
+ $url = "$scheme://$domain$uri";
3241
+ }
3242
+ $url;
3243
+}
3244
+
3245
sub new {
3246
my ($class, $url) = @_;
3247
$url =~ s!/+$!!;
@@ -3255,10 +3274,11 @@ sub new {
3274
$Git::SVN::Prompt::_no_auth_cache = 1;
3275
}
3276
} # no warnings 'once'
3258
- my $self = SVN::Ra->new(url => $url, auth => $baton,
3277
+ my $self = SVN::Ra->new(url => escape_url($url), auth => $baton,
3278
config => $config,
3279
pool => SVN::Pool->new,
3280
auth_provider_callbacks => $callbacks);
3281
+ $self->{url} = $url;
3282
$self->{svn_path} = $url;
3283
$self->{repos_root} = $self->get_repos_root;
3284
$self->{svn_path} =~ s#^\Q$self->{repos_root}\E(/|$)##;
@@ -3384,7 +3404,7 @@ sub gs_do_switch {
3404
3405
my $full_url = $self->{url};
3406
my $old_url = $full_url;
3387
- $full_url .= "/$path" if length $path;
3407
+ $full_url .= '/' . escape_uri_only($path) if length $path;
3408
my ($ra, $reparented);
3409
if ($old_url ne $full_url) {
3410
if ($old_url !~ m#^svn(\+ssh)?://#) {
t/t9118-git-svn-funky-branch-names.sh
new
+40
@@ -0,0 +1,40 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2007 Eric Wong
4
+#
5
+
6
+test_description='git-svn funky branch names'
7
+. ./lib-git-svn.sh
8
+
9
+test_expect_success 'setup svnrepo' "
10
+ mkdir project project/trunk project/branches project/tags &&
11
+ echo foo > project/trunk/foo &&
12
+ svn import -m '$test_description' project \"$svnrepo/pr ject\" &&
13
+ rm -rf project &&
14
+ svn cp -m 'fun' \"$svnrepo/pr ject/trunk\" \
15
+ \"$svnrepo/pr ject/branches/fun plugin\" &&
16
+ svn cp -m 'more fun!' \"$svnrepo/pr ject/branches/fun plugin\" \
17
+ \"$svnrepo/pr ject/branches/more fun plugin!\" &&
18
+ start_httpd
19
+ "
20
+
21
+test_expect_success 'test clone with funky branch names' "
22
+ git svn clone -s \"$svnrepo/pr ject\" project &&
23
+ cd project &&
24
+ git rev-parse 'refs/remotes/fun%20plugin' &&
25
+ git rev-parse 'refs/remotes/more%20fun%20plugin!' &&
26
+ cd ..
27
+ "
28
+
29
+test_expect_success 'test dcommit to funky branch' "
30
+ cd project &&
31
+ git reset --hard 'refs/remotes/more%20fun%20plugin!' &&
32
+ echo hello >> foo &&
33
+ git commit -m 'hello' -- foo &&
34
+ git svn dcommit &&
35
+ cd ..
36
+ "
37
+
38
+stop_httpd
39
+
40
+test_done