Skip to content

Commit a0d3ab9

Browse files
committed
Merge git://git.bogomips.org/git-svn
* git://git.bogomips.org/git-svn: git-svn: proper detection of bare repositories git-svn: respect i18n.commitencoding config git-svn: don't escape tilde ('~') for http(s) URLs
2 parents 59d8cb4 + 6e5121f commit a0d3ab9

File tree

3 files changed

+120
-11
lines changed

3 files changed

+120
-11
lines changed

git-svn.perl

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,13 @@ BEGIN
223223
"but it is not a directory\n";
224224
}
225225
my $git_dir = delete $ENV{GIT_DIR};
226-
chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/));
227-
unless (length $cdup) {
228-
die "Already at toplevel, but $git_dir ",
229-
"not found '$cdup'\n";
230-
}
226+
my $cdup = undef;
227+
git_cmd_try {
228+
$cdup = command_oneline(qw/rev-parse --show-cdup/);
229+
$git_dir = '.' unless ($cdup);
230+
chomp $cdup if ($cdup);
231+
$cdup = "." unless ($cdup && length $cdup);
232+
} "Already at toplevel, but $git_dir not found\n";
231233
chdir $cdup or die "Unable to chdir up to '$cdup'\n";
232234
unless (-d $git_dir) {
233235
die "$git_dir still not found after going to ",
@@ -852,7 +854,7 @@ sub escape_uri_only {
852854
my ($uri) = @_;
853855
my @tmp;
854856
foreach (split m{/}, $uri) {
855-
s/([^\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
857+
s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
856858
push @tmp, $_;
857859
}
858860
join('/', @tmp);
@@ -1136,9 +1138,19 @@ sub get_commit_entry {
11361138
system($editor, $commit_editmsg);
11371139
}
11381140
rename $commit_editmsg, $commit_msg or croak $!;
1139-
open $log_fh, '<', $commit_msg or croak $!;
1140-
{ local $/; chomp($log_entry{log} = <$log_fh>); }
1141-
close $log_fh or croak $!;
1141+
{
1142+
# SVN requires messages to be UTF-8 when entering the repo
1143+
local $/;
1144+
open $log_fh, '<', $commit_msg or croak $!;
1145+
binmode $log_fh;
1146+
chomp($log_entry{log} = <$log_fh>);
1147+
1148+
if (my $enc = Git::config('i18n.commitencoding')) {
1149+
require Encode;
1150+
Encode::from_to($log_entry{log}, $enc, 'UTF-8');
1151+
}
1152+
close $log_fh or croak $!;
1153+
}
11421154
unlink $commit_msg;
11431155
\%log_entry;
11441156
}
@@ -2273,6 +2285,14 @@ sub do_git_commit {
22732285
}
22742286
defined(my $pid = open3(my $msg_fh, my $out_fh, '>&STDERR', @exec))
22752287
or croak $!;
2288+
binmode $msg_fh;
2289+
2290+
# we always get UTF-8 from SVN, but we may want our commits in
2291+
# a different encoding.
2292+
if (my $enc = Git::config('i18n.commitencoding')) {
2293+
require Encode;
2294+
Encode::from_to($log_entry->{log}, 'UTF-8', $enc);
2295+
}
22762296
print $msg_fh $log_entry->{log} or croak $!;
22772297
restore_commit_header_env($old_env);
22782298
unless ($self->no_metadata) {
@@ -3537,7 +3557,7 @@ sub repo_path {
35373557
sub url_path {
35383558
my ($self, $path) = @_;
35393559
if ($self->{url} =~ m#^https?://#) {
3540-
$path =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
3560+
$path =~ s/([^~a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
35413561
}
35423562
$self->{url} . '/' . $self->repo_path($path);
35433563
}
@@ -3890,7 +3910,7 @@ sub escape_uri_only {
38903910
my ($uri) = @_;
38913911
my @tmp;
38923912
foreach (split m{/}, $uri) {
3893-
s/([^\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
3913+
s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
38943914
push @tmp, $_;
38953915
}
38963916
join('/', @tmp);

t/t9100-git-svn-basic.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,13 @@ test_expect_success 'able to set-tree to a subdirectory' "
265265
test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
266266
"
267267

268+
test_expect_success 'git-svn works in a bare repository' '
269+
mkdir bare-repo &&
270+
( cd bare-repo &&
271+
git init --bare &&
272+
GIT_DIR=. git svn init "$svnrepo" &&
273+
git svn fetch ) &&
274+
rm -rf bare-repo
275+
'
276+
268277
test_done
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2008 Eric Wong
4+
5+
test_description='git svn honors i18n.commitEncoding in config'
6+
7+
. ./lib-git-svn.sh
8+
9+
compare_git_head_with () {
10+
nr=`wc -l < "$1"`
11+
a=7
12+
b=$(($a + $nr - 1))
13+
git cat-file commit HEAD | sed -ne "$a,${b}p" >current &&
14+
test_cmp current "$1"
15+
}
16+
17+
compare_svn_head_with () {
18+
LC_ALL=en_US.UTF-8 svn log --limit 1 `git svn info --url` | \
19+
sed -e 1,3d -e "/^-\+\$/d" >current &&
20+
test_cmp current "$1"
21+
}
22+
23+
for H in ISO-8859-1 EUCJP ISO-2022-JP
24+
do
25+
test_expect_success "$H setup" '
26+
mkdir $H &&
27+
svn import -m "$H test" $H "$svnrepo"/$H &&
28+
git svn clone "$svnrepo"/$H $H
29+
'
30+
done
31+
32+
for H in ISO-8859-1 EUCJP ISO-2022-JP
33+
do
34+
test_expect_success "$H commit on git side" '
35+
(
36+
cd $H &&
37+
git config i18n.commitencoding $H &&
38+
git checkout -b t refs/remotes/git-svn &&
39+
echo $H >F &&
40+
git add F &&
41+
git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
42+
E=$(git cat-file commit HEAD | sed -ne "s/^encoding //p") &&
43+
test "z$E" = "z$H"
44+
compare_git_head_with "$TEST_DIRECTORY"/t3900/$H.txt
45+
)
46+
'
47+
done
48+
49+
for H in ISO-8859-1 EUCJP ISO-2022-JP
50+
do
51+
test_expect_success "$H dcommit to svn" '
52+
(
53+
cd $H &&
54+
git svn dcommit &&
55+
git cat-file commit HEAD | grep git-svn-id: &&
56+
E=$(git cat-file commit HEAD | sed -ne "s/^encoding //p") &&
57+
test "z$E" = "z$H" &&
58+
compare_git_head_with "$TEST_DIRECTORY"/t3900/$H.txt
59+
)
60+
'
61+
done
62+
63+
test_expect_success 'ISO-8859-1 should match UTF-8 in svn' '
64+
(
65+
cd ISO-8859-1 &&
66+
compare_svn_head_with "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
67+
)
68+
'
69+
70+
for H in EUCJP ISO-2022-JP
71+
do
72+
test_expect_success '$H should match UTF-8 in svn' '
73+
(
74+
cd $H &&
75+
compare_svn_head_with "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
76+
)
77+
'
78+
done
79+
80+
test_done

0 commit comments

Comments
 (0)