Skip to content

Commit 29633bb

Browse files
Eric Wonggitster
authored andcommitted
git-svn: fix commiting renames over DAV with funky file names
Renaming files with non-URI friendly characters caused breakage when committing to DAV repositories (over http(s)). Even if I try leaving out the $self->{url} from the return value of url_path(), a partial (without host), unescaped path name does not work. Filenames for DAV repos need to be URI-encoded before being passed to the library. Since this bug did not affect file:// and svn:// repos, the git-svn test library needed to be expanded to include support for starting Apache with mod_dav_svn enabled. This new test is not enabled by default, but can be enabled by setting SVN_HTTPD_PORT to any available TCP/IP port on 127.0.0.1. Additionally, for running this test, the following variables (with defaults shown) can be changed for the suitable system. The default values are set for Debian systems: SVN_HTTPD_MODULE_PATH=/usr/lib/apache2/modules SVN_HTTPD_PATH=/usr/sbin/apache2 Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 99c01de commit 29633bb

File tree

4 files changed

+194
-0
lines changed

4 files changed

+194
-0
lines changed

git-svn.perl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,9 @@ sub repo_path {
27242724

27252725
sub url_path {
27262726
my ($self, $path) = @_;
2727+
if ($self->{url} =~ m#^https?://#) {
2728+
$path =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
2729+
}
27272730
$self->{url} . '/' . $self->repo_path($path);
27282731
}
27292732

t/lib-git-svn.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,37 @@ svnrepo="file://$svnrepo"
4848
poke() {
4949
test-chmtime +1 "$1"
5050
}
51+
52+
SVN_HTTPD_MODULE_PATH=${SVN_HTTPD_MODULE_PATH-'/usr/lib/apache2/modules'}
53+
SVN_HTTPD_PATH=${SVN_HTTPD_PATH-'/usr/sbin/apache2'}
54+
55+
start_httpd () {
56+
if test -z "$SVN_HTTPD_PORT"
57+
then
58+
echo >&2 'SVN_HTTPD_PORT is not defined!'
59+
return
60+
fi
61+
62+
mkdir "$GIT_DIR"/logs
63+
64+
cat > "$GIT_DIR/httpd.conf" <<EOF
65+
ServerName "git-svn test"
66+
ServerRoot "$GIT_DIR"
67+
DocumentRoot "$GIT_DIR"
68+
PidFile "$GIT_DIR/httpd.pid"
69+
Listen 127.0.0.1:$SVN_HTTPD_PORT
70+
LoadModule dav_module $SVN_HTTPD_MODULE_PATH/mod_dav.so
71+
LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so
72+
<Location /svn>
73+
DAV svn
74+
SVNPath $rawsvnrepo
75+
</Location>
76+
EOF
77+
"$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start
78+
svnrepo=http://127.0.0.1:$SVN_HTTPD_PORT/svn
79+
}
80+
81+
stop_httpd () {
82+
test -z "$SVN_HTTPD_PORT" && return
83+
"$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop
84+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2007 Eric Wong
4+
5+
6+
test_description='git-svn dcommit can commit renames of files with ugly names'
7+
8+
. ./lib-git-svn.sh
9+
10+
test_expect_success 'load repository with strange names' "
11+
svnadmin load -q $rawsvnrepo < ../t9115/funky-names.dump &&
12+
start_httpd
13+
"
14+
15+
test_expect_success 'init and fetch repository' "
16+
git svn init $svnrepo &&
17+
git svn fetch &&
18+
git reset --hard git-svn
19+
"
20+
21+
test_expect_success 'create file in existing ugly and empty dir' '
22+
mkdir "#{bad_directory_name}" &&
23+
echo hi > "#{bad_directory_name}/ foo" &&
24+
git update-index --add "#{bad_directory_name}/ foo" &&
25+
git commit -m "new file in ugly parent" &&
26+
git svn dcommit
27+
'
28+
29+
test_expect_success 'rename ugly file' '
30+
git mv "#{bad_directory_name}/ foo" "file name with feces" &&
31+
git commit -m "rename ugly file" &&
32+
git svn dcommit
33+
'
34+
35+
test_expect_success 'rename pretty file' '
36+
echo :x > pretty &&
37+
git update-index --add pretty &&
38+
git commit -m "pretty :x" &&
39+
git svn dcommit &&
40+
mkdir regular_dir_name &&
41+
git mv pretty regular_dir_name/pretty &&
42+
git commit -m "moved pretty file" &&
43+
git svn dcommit
44+
'
45+
46+
test_expect_success 'rename pretty file into ugly one' '
47+
git mv regular_dir_name/pretty "#{bad_directory_name}/ booboo" &&
48+
git commit -m booboo &&
49+
git svn dcommit
50+
'
51+
52+
stop_httpd
53+
54+
test_done

t/t9115/funky-names.dump

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
SVN-fs-dump-format-version: 2
2+
3+
UUID: 819c44fe-2bcc-4066-88e4-985e2bc0b418
4+
5+
Revision-number: 0
6+
Prop-content-length: 56
7+
Content-length: 56
8+
9+
K 8
10+
svn:date
11+
V 27
12+
2007-07-12T07:54:26.062914Z
13+
PROPS-END
14+
15+
Revision-number: 1
16+
Prop-content-length: 152
17+
Content-length: 152
18+
19+
K 7
20+
svn:log
21+
V 44
22+
what will those wacky people think of next?
23+
24+
K 10
25+
svn:author
26+
V 12
27+
normalperson
28+
K 8
29+
svn:date
30+
V 27
31+
2007-07-12T08:00:05.011573Z
32+
PROPS-END
33+
34+
Node-path: leading space
35+
Node-kind: dir
36+
Node-action: add
37+
Prop-content-length: 10
38+
Content-length: 10
39+
40+
PROPS-END
41+
42+
43+
Node-path: leading space file
44+
Node-kind: file
45+
Node-action: add
46+
Prop-content-length: 10
47+
Text-content-length: 5
48+
Text-content-md5: e4fa20c67542cdc21271e08d329397ab
49+
Content-length: 15
50+
51+
PROPS-END
52+
ugly
53+
54+
55+
Node-path: #{bad_directory_name}
56+
Node-kind: dir
57+
Node-action: add
58+
Prop-content-length: 10
59+
Content-length: 10
60+
61+
PROPS-END
62+
63+
64+
Node-path: #{cool_name}
65+
Node-kind: file
66+
Node-action: add
67+
Prop-content-length: 10
68+
Text-content-length: 18
69+
Text-content-md5: 87dac40ca337dfa3dcc8911388c3ddda
70+
Content-length: 28
71+
72+
PROPS-END
73+
strange name here
74+
75+
76+
Node-path: dir name with spaces
77+
Node-kind: dir
78+
Node-action: add
79+
Prop-content-length: 10
80+
Content-length: 10
81+
82+
PROPS-END
83+
84+
85+
Node-path: file name with spaces
86+
Node-kind: file
87+
Node-action: add
88+
Prop-content-length: 10
89+
Text-content-length: 7
90+
Text-content-md5: c1f10cfd640618484a2a475c11410fd3
91+
Content-length: 17
92+
93+
PROPS-END
94+
spaces
95+
96+
97+
Node-path: regular_dir_name
98+
Node-kind: dir
99+
Node-action: add
100+
Prop-content-length: 10
101+
Content-length: 10
102+
103+
PROPS-END

0 commit comments

Comments
 (0)