Skip to content

Commit 379862e

Browse files
srwalterEric Wong
authored andcommitted
git-svn.perl: fix a false-positive in the "already exists" test
open_or_add_dir checks to see if the directory already exists or not. If it already exists and is not a directory, then we fail. However, open_or_add_dir did not previously account for the possibility that the path did exist as a file, but is deleted in the current commit. In order to prevent this legitimate case from failing, open_or_add_dir needs to know what files are deleted in the current commit. Unfortunately that information has to be plumbed through a couple of layers. Signed-off-by: Steven Walter <[email protected]> Acked-by: Eric Wong <[email protected]>
1 parent 5ec514b commit 379862e

File tree

2 files changed

+44
-32
lines changed

2 files changed

+44
-32
lines changed

git-svn.perl

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,7 +5137,7 @@ sub rmdirs {
51375137
}
51385138

51395139
sub open_or_add_dir {
5140-
my ($self, $full_path, $baton) = @_;
5140+
my ($self, $full_path, $baton, $deletions) = @_;
51415141
my $t = $self->{types}->{$full_path};
51425142
if (!defined $t) {
51435143
die "$full_path not known in r$self->{r} or we have a bug!\n";
@@ -5146,7 +5146,7 @@ sub open_or_add_dir {
51465146
no warnings 'once';
51475147
# SVN::Node::none and SVN::Node::file are used only once,
51485148
# so we're shutting up Perl's warnings about them.
5149-
if ($t == $SVN::Node::none) {
5149+
if ($t == $SVN::Node::none || defined($deletions->{$full_path})) {
51505150
return $self->add_directory($full_path, $baton,
51515151
undef, -1, $self->{pool});
51525152
} elsif ($t == $SVN::Node::dir) {
@@ -5161,17 +5161,18 @@ sub open_or_add_dir {
51615161
}
51625162

51635163
sub ensure_path {
5164-
my ($self, $path) = @_;
5164+
my ($self, $path, $deletions) = @_;
51655165
my $bat = $self->{bat};
51665166
my $repo_path = $self->repo_path($path);
51675167
return $bat->{''} unless (length $repo_path);
5168+
51685169
my @p = split m#/+#, $repo_path;
51695170
my $c = shift @p;
5170-
$bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''});
5171+
$bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''}, $deletions);
51715172
while (@p) {
51725173
my $c0 = $c;
51735174
$c .= '/' . shift @p;
5174-
$bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0});
5175+
$bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0}, $deletions);
51755176
}
51765177
return $bat->{$c};
51775178
}
@@ -5228,9 +5229,9 @@ sub apply_autoprops {
52285229
}
52295230

52305231
sub A {
5231-
my ($self, $m) = @_;
5232+
my ($self, $m, $deletions) = @_;
52325233
my ($dir, $file) = split_path($m->{file_b});
5233-
my $pbat = $self->ensure_path($dir);
5234+
my $pbat = $self->ensure_path($dir, $deletions);
52345235
my $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat,
52355236
undef, -1);
52365237
print "\tA\t$m->{file_b}\n" unless $::_q;
@@ -5240,9 +5241,9 @@ sub A {
52405241
}
52415242

52425243
sub C {
5243-
my ($self, $m) = @_;
5244+
my ($self, $m, $deletions) = @_;
52445245
my ($dir, $file) = split_path($m->{file_b});
5245-
my $pbat = $self->ensure_path($dir);
5246+
my $pbat = $self->ensure_path($dir, $deletions);
52465247
my $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat,
52475248
$self->url_path($m->{file_a}), $self->{r});
52485249
print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q;
@@ -5259,9 +5260,9 @@ sub delete_entry {
52595260
}
52605261

52615262
sub R {
5262-
my ($self, $m) = @_;
5263+
my ($self, $m, $deletions) = @_;
52635264
my ($dir, $file) = split_path($m->{file_b});
5264-
my $pbat = $self->ensure_path($dir);
5265+
my $pbat = $self->ensure_path($dir, $deletions);
52655266
my $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat,
52665267
$self->url_path($m->{file_a}), $self->{r});
52675268
print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q;
@@ -5270,14 +5271,14 @@ sub R {
52705271
$self->close_file($fbat,undef,$self->{pool});
52715272

52725273
($dir, $file) = split_path($m->{file_a});
5273-
$pbat = $self->ensure_path($dir);
5274+
$pbat = $self->ensure_path($dir, $deletions);
52745275
$self->delete_entry($m->{file_a}, $pbat);
52755276
}
52765277

52775278
sub M {
5278-
my ($self, $m) = @_;
5279+
my ($self, $m, $deletions) = @_;
52795280
my ($dir, $file) = split_path($m->{file_b});
5280-
my $pbat = $self->ensure_path($dir);
5281+
my $pbat = $self->ensure_path($dir, $deletions);
52815282
my $fbat = $self->open_file($self->repo_path($m->{file_b}),
52825283
$pbat,$self->{r},$self->{pool});
52835284
print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q;
@@ -5347,9 +5348,9 @@ sub chg_file {
53475348
}
53485349

53495350
sub D {
5350-
my ($self, $m) = @_;
5351+
my ($self, $m, $deletions) = @_;
53515352
my ($dir, $file) = split_path($m->{file_b});
5352-
my $pbat = $self->ensure_path($dir);
5353+
my $pbat = $self->ensure_path($dir, $deletions);
53535354
print "\tD\t$m->{file_b}\n" unless $::_q;
53545355
$self->delete_entry($m->{file_b}, $pbat);
53555356
}
@@ -5382,10 +5383,18 @@ sub apply_diff {
53825383
my ($self) = @_;
53835384
my $mods = $self->{mods};
53845385
my %o = ( D => 0, C => 1, R => 2, A => 3, M => 4, T => 5 );
5386+
my %deletions;
5387+
5388+
foreach my $m (@$mods) {
5389+
if ($m->{chg} eq "D") {
5390+
$deletions{$m->{file_b}} = 1;
5391+
}
5392+
}
5393+
53855394
foreach my $m (sort { $o{$a->{chg}} <=> $o{$b->{chg}} } @$mods) {
53865395
my $f = $m->{chg};
53875396
if (defined $o{$f}) {
5388-
$self->$f($m);
5397+
$self->$f($m, \%deletions);
53895398
} else {
53905399
fatal("Invalid change type: $f");
53915400
}

t/t9100-git-svn-basic.sh

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ test_expect_success "$name" '
9292
echo yyy > bar/zzz/yyy &&
9393
git update-index --add bar/zzz/yyy &&
9494
git commit -m "$name" &&
95-
test_must_fail git svn set-tree --find-copies-harder --rmdir \
96-
${remotes_git_svn}..mybranch3' || true
97-
95+
git svn set-tree --find-copies-harder --rmdir \
96+
${remotes_git_svn}..mybranch3 &&
97+
svn_cmd up "$SVN_TREE" &&
98+
test -d "$SVN_TREE"/bar/zzz &&
99+
test -e "$SVN_TREE"/bar/zzz/yyy ' || true
98100

99101
name='detect node change from directory to file #2'
100102
test_expect_success "$name" '
@@ -134,10 +136,10 @@ test_expect_success "$name" '
134136
test -x "$SVN_TREE"/exec.sh'
135137

136138

137-
name='executable file becomes a symlink to bar/zzz (file)'
139+
name='executable file becomes a symlink to file'
138140
test_expect_success "$name" '
139141
rm exec.sh &&
140-
ln -s bar/zzz exec.sh &&
142+
ln -s file exec.sh &&
141143
git update-index exec.sh &&
142144
git commit -m "$name" &&
143145
git svn set-tree --find-copies-harder --rmdir \
@@ -148,14 +150,14 @@ test_expect_success "$name" '
148150
name='new symlink is added to a file that was also just made executable'
149151

150152
test_expect_success "$name" '
151-
chmod +x bar/zzz &&
152-
ln -s bar/zzz exec-2.sh &&
153-
git update-index --add bar/zzz exec-2.sh &&
153+
chmod +x file &&
154+
ln -s file exec-2.sh &&
155+
git update-index --add file exec-2.sh &&
154156
git commit -m "$name" &&
155157
git svn set-tree --find-copies-harder --rmdir \
156158
${remotes_git_svn}..mybranch5 &&
157159
svn_cmd up "$SVN_TREE" &&
158-
test -x "$SVN_TREE"/bar/zzz &&
160+
test -x "$SVN_TREE"/file &&
159161
test -h "$SVN_TREE"/exec-2.sh'
160162

161163
name='modify a symlink to become a file'
@@ -195,14 +197,15 @@ name='check imported tree checksums expected tree checksums'
195197
rm -f expected
196198
if test_have_prereq UTF8
197199
then
198-
echo tree bf522353586b1b883488f2bc73dab0d9f774b9a9 > expected
200+
echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected
199201
fi
200202
cat >> expected <<\EOF
201-
tree 83654bb36f019ae4fe77a0171f81075972087624
202-
tree 031b8d557afc6fea52894eaebb45bec52f1ba6d1
203-
tree 0b094cbff17168f24c302e297f55bfac65eb8bd3
204-
tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
205-
tree 56a30b966619b863674f5978696f4a3594f2fca9
203+
tree c3322890dcf74901f32d216f05c5044f670ce632
204+
tree d3ccd5035feafd17b030c5732e7808cc49122853
205+
tree d03e1630363d4881e68929d532746b20b0986b83
206+
tree 149d63cd5878155c846e8c55d7d8487de283f89e
207+
tree 312b76e4f64ce14893aeac8591eb3960b065e247
208+
tree 149d63cd5878155c846e8c55d7d8487de283f89e
206209
tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
207210
tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
208211
EOF

0 commit comments

Comments
 (0)