Skip to content

Commit 3235b70

Browse files
ddkilzerEric Wong
authored andcommitted
git-svn: fix fetch with deleted tag
Currently git-svn assumes that two tags created from the same revision will have the same repo url, so it uses a ref to the tag without checking that its url matches the current url. This causes issues when fetching an svn repo where a tag was created, deleted, and then recreated under the following circumstances: - Both tags were copied from the same revision. - Both tags had the same name. - Both tags had different repository paths. - [Optional] Both tags have a file with the same name but different content. When all four conditions are met, a checksum mismatch error occurs because the content of two files with the same path differs (see t/t9155--git-svn-fetch-deleted-tag.sh): Checksum mismatch: ChangeLog 065854.... expected: ce771b.... got: 9563fd.... When only the first three conditions are met, no error occurs but the tag in git matches the first (deleted) tag instead of the last (most recent) tag (see t/t9156-git-svn-fetch-deleted-tag-2.sh). The fix is to verify that the repo url for the ref matches the current url. If the urls do not match, then a "tail" is grown on the tag name by appending a dash and rechecking the new ref's repo url until either a matching repo url is found or a new tag is created. Signed-off-by: David D. Kilzer <ddkilzer@kilzer.net> Acked-by: Eric Wong <normalperson@yhbt.net>
1 parent 54fb7f9 commit 3235b70

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

git-svn.perl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,14 +2963,25 @@ sub other_gs {
29632963
$ref_id .= "\@$r";
29642964
# just grow a tail if we're not unique enough :x
29652965
$ref_id .= '-' while find_ref($ref_id);
2966-
print STDERR "Initializing parent: $ref_id\n" unless $::_q > 1;
29672966
my ($u, $p, $repo_id) = ($new_url, '', $ref_id);
29682967
if ($u =~ s#^\Q$url\E(/|$)##) {
29692968
$p = $u;
29702969
$u = $url;
29712970
$repo_id = $self->{repo_id};
29722971
}
2973-
$gs = Git::SVN->init($u, $p, $repo_id, $ref_id, 1);
2972+
while (1) {
2973+
# It is possible to tag two different subdirectories at
2974+
# the same revision. If the url for an existing ref
2975+
# does not match, we must either find a ref with a
2976+
# matching url or create a new ref by growing a tail.
2977+
$gs = Git::SVN->init($u, $p, $repo_id, $ref_id, 1);
2978+
my (undef, $max_commit) = $gs->rev_map_max(1);
2979+
last if (!$max_commit);
2980+
my ($url) = ::cmt_metadata($max_commit);
2981+
last if ($url eq $gs->full_url);
2982+
$ref_id .= '-';
2983+
}
2984+
print STDERR "Initializing parent: $ref_id\n" unless $::_q > 1;
29742985
}
29752986
$gs
29762987
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
3+
test_description='git svn fetch deleted tag'
4+
5+
. ./lib-git-svn.sh
6+
7+
test_expect_success 'setup svn repo' '
8+
mkdir -p import/trunk/subdir &&
9+
mkdir -p import/branches &&
10+
mkdir -p import/tags &&
11+
echo "base" >import/trunk/subdir/file &&
12+
svn_cmd import -m "import for git svn" import "$svnrepo" &&
13+
rm -rf import &&
14+
15+
svn_cmd mkdir --parents -m "create mybranch directory" "$svnrepo/branches/mybranch" &&
16+
svn_cmd cp -m "create branch mybranch" "$svnrepo/trunk" "$svnrepo/branches/mybranch/trunk" &&
17+
18+
svn_cmd co "$svnrepo/trunk" svn_project &&
19+
(cd svn_project &&
20+
echo "trunk change" >>subdir/file &&
21+
svn_cmd ci -m "trunk change" subdir/file &&
22+
23+
svn_cmd switch "$svnrepo/branches/mybranch/trunk" &&
24+
echo "branch change" >>subdir/file &&
25+
svn_cmd ci -m "branch change" subdir/file
26+
) &&
27+
28+
svn_cmd cp -m "create mytag attempt 1" -r5 "$svnrepo/trunk/subdir" "$svnrepo/tags/mytag" &&
29+
svn_cmd rm -m "delete mytag attempt 1" "$svnrepo/tags/mytag" &&
30+
svn_cmd cp -m "create mytag attempt 2" -r5 "$svnrepo/branches/mybranch/trunk/subdir" "$svnrepo/tags/mytag"
31+
'
32+
33+
test_expect_success 'fetch deleted tags from same revision with checksum error' '
34+
git svn init --stdlayout "$svnrepo" git_project &&
35+
cd git_project &&
36+
git svn fetch &&
37+
38+
git diff --exit-code mybranch:trunk/subdir/file tags/mytag:file &&
39+
git diff --exit-code master:subdir/file tags/mytag^:file
40+
'
41+
42+
test_done
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
3+
test_description='git svn fetch deleted tag 2'
4+
5+
. ./lib-git-svn.sh
6+
7+
test_expect_success 'setup svn repo' '
8+
mkdir -p import/branches &&
9+
mkdir -p import/tags &&
10+
mkdir -p import/trunk/subdir1 &&
11+
mkdir -p import/trunk/subdir2 &&
12+
mkdir -p import/trunk/subdir3 &&
13+
echo "file1" >import/trunk/subdir1/file &&
14+
echo "file2" >import/trunk/subdir2/file &&
15+
echo "file3" >import/trunk/subdir3/file &&
16+
svn_cmd import -m "import for git svn" import "$svnrepo" &&
17+
rm -rf import &&
18+
19+
svn_cmd co "$svnrepo/trunk" svn_project &&
20+
(cd svn_project &&
21+
echo "change1" >>subdir1/file &&
22+
echo "change2" >>subdir2/file &&
23+
echo "change3" >>subdir3/file &&
24+
svn_cmd ci -m "change" .
25+
) &&
26+
27+
svn_cmd cp -m "create mytag 1" -r2 "$svnrepo/trunk/subdir1" "$svnrepo/tags/mytag" &&
28+
svn_cmd rm -m "delete mytag 1" "$svnrepo/tags/mytag" &&
29+
svn_cmd cp -m "create mytag 2" -r2 "$svnrepo/trunk/subdir2" "$svnrepo/tags/mytag" &&
30+
svn_cmd rm -m "delete mytag 2" "$svnrepo/tags/mytag" &&
31+
svn_cmd cp -m "create mytag 3" -r2 "$svnrepo/trunk/subdir3" "$svnrepo/tags/mytag"
32+
'
33+
34+
test_expect_success 'fetch deleted tags from same revision with no checksum error' '
35+
git svn init --stdlayout "$svnrepo" git_project &&
36+
cd git_project &&
37+
git svn fetch &&
38+
39+
git diff --exit-code master:subdir3/file tags/mytag:file &&
40+
git diff --exit-code master:subdir2/file tags/mytag^:file &&
41+
git diff --exit-code master:subdir1/file tags/mytag^^:file
42+
'
43+
44+
test_done

0 commit comments

Comments
 (0)