@matheusbsbs / matheus-bagliano / commits / 8a603774de
Fork 0

git-svn: fix several fetch bugs related to repeated invocations

We no longer delete the top-level directory even if it got deleted from the upstream repository. In gs_do_update; we double-check that the path we're tracking exists at both endpoints before proceeding. We have also added additional protection against fetching revisions out-of-order. To simplify our internal interfaces, I've disabled passing the 'recursive' flag to the gs_do_{switch,update} wrapper functions since we always want it in git-svn. We also pass the entire Git::SVN object rather than just the path because it helped me debug. When printing progress, the refname is printed out to make it less confusing when multi-fetch is running. Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Jan 31, 2007 at 02:45 UTC 8a603774def11e5a90ae2dbbc0c8d4abacdb2d99
2 files changed +43 -15
git-svn.perl
+30 -12
@@ -981,6 +981,12 @@ sub full_url {
981
982 sub do_git_commit {
983 my ($self, $log_entry) = @_;
984 + my $lr = $self->last_rev;
985 + if (defined $lr && $lr >= $log_entry->{revision}) {
986 + die "Last fetched revision of ", $self->refname,
987 + " was r$lr, but we are about to fetch: ",
988 + "r$log_entry->{revision}!\n";
989 + }
990 if (my $c = $self->rev_db_get($log_entry->{revision})) {
991 croak "$log_entry->{revision} = $c already exists! ",
992 "Why are we refetching it?\n";
@@ -1024,7 +1030,7 @@ sub do_git_commit {
1030
1031 $self->{last_rev} = $log_entry->{revision};
1032 $self->{last_commit} = $commit;
1027 - print "r$log_entry->{revision} = $commit\n";
1033 + print "r$log_entry->{revision} = $commit ($self->{ref_id})\n";
1034 return $commit;
1035 }
1036
@@ -1121,14 +1127,13 @@ sub find_parent_branch {
1127 # at the moment), so we can't rely on it
1128 $self->{last_commit} = $parent;
1129 $ed = SVN::Git::Fetcher->new($self);
1124 - $gs->ra->gs_do_switch($r0, $rev, $gs->{path}, 1,
1130 + $gs->ra->gs_do_switch($r0, $rev, $gs,
1131 $self->full_url, $ed)
1132 or die "SVN connection failed somewhere...\n";
1133 } else {
1134 print STDERR "Following parent with do_update\n";
1135 $ed = SVN::Git::Fetcher->new($self);
1130 - $self->ra->gs_do_update($rev, $rev, $self->{path},
1131 - 1, $ed)
1136 + $self->ra->gs_do_update($rev, $rev, $self, $ed)
1137 or die "SVN connection failed somewhere...\n";
1138 }
1139 print STDERR "Successfully followed parent\n";
@@ -1170,8 +1175,7 @@ sub do_fetch {
1175 $ed = SVN::Git::Fetcher->new($self);
1176 $ed->{new_fetch} = 1;
1177 }
1173 - unless ($self->ra->gs_do_update($last_rev, $rev,
1174 - $self->{path}, 1, $ed)) {
1178 + unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
1179 die "SVN connection failed somewhere...\n";
1180 }
1181 $self->make_log_entry($rev, \@parents, $ed);
@@ -1616,6 +1620,8 @@ sub delete_entry {
1620 my ($self, $path, $rev, $pb) = @_;
1621
1622 my $gpath = $self->git_path($path);
1623 + return undef if ($gpath eq '');
1624 +
1625 # remove entire directories.
1626 if (command('ls-tree', $self->{c}, '--', $gpath) =~ /^040000 tree/) {
1627 my ($ls, $ctx) = command_output_pipe(qw/ls-tree
@@ -2233,12 +2239,23 @@ sub uuid {
2239 }
2240
2241 sub gs_do_update {
2236 - my ($self, $rev_a, $rev_b, $path, $recurse, $editor) = @_;
2242 + my ($self, $rev_a, $rev_b, $gs, $editor) = @_;
2243 + my $new = ($rev_a == $rev_b);
2244 + my $path = $gs->{path};
2245 +
2246 + my $ta = $self->check_path($path, $rev_a);
2247 + my $tb = $new ? $ta : $self->check_path($path, $rev_b);
2248 + return 1 if ($tb != $SVN::Node::dir && $ta != $SVN::Node::dir);
2249 + if ($ta == $SVN::Node::none) {
2250 + $rev_a = $rev_b;
2251 + $new = 1;
2252 + }
2253 +
2254 my $pool = SVN::Pool->new;
2255 $editor->set_path_strip($path);
2256 my (@pc) = split m#/#, $path;
2257 my $reporter = $self->do_update($rev_b, (@pc ? shift @pc : ''),
2241 - $recurse, $editor, $pool);
2258 + 1, $editor, $pool);
2259 my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
2260
2261 # Since we can't rely on svn_ra_reparent being available, we'll
@@ -2253,7 +2270,6 @@ sub gs_do_update {
2270 }
2271 die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
2272
2256 - my $new = ($rev_a == $rev_b);
2273 $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
2274
2275 $reporter->finish_report($pool);
@@ -2264,7 +2280,8 @@ sub gs_do_update {
2280 # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and
2281 # svn_ra_reparent didn't work before 1.4)
2282 sub gs_do_switch {
2267 - my ($self, $rev_a, $rev_b, $path, $recurse, $url_b, $editor) = @_;
2283 + my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_;
2284 + my $path = $gs->{path};
2285 my $pool = SVN::Pool->new;
2286
2287 my $full_url = $self->{url};
@@ -2282,8 +2299,7 @@ sub gs_do_switch {
2299 }
2300 }
2301 $ra ||= $self;
2285 - my $reporter = $ra->do_switch($rev_b, '',
2286 - $recurse, $url_b, $editor, $pool);
2302 + my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
2303 my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
2304 $reporter->set_path('', $rev_a, 0, @lock, $pool);
2305 $reporter->finish_report($pool);
@@ -2333,6 +2349,8 @@ sub gs_fetch_loop_common {
2349 if ($paths) {
2350 $gs->match_paths($paths) or next;
2351 }
2352 + my $lr = $gs->last_rev;
2353 + next if defined $lr && $lr >= $r;
2354 next if defined $gs->rev_db_get($r);
2355 if (my $log_entry = $gs->do_fetch($paths, $r)) {
2356 $gs->do_git_commit($log_entry);
t/t9104-git-svn-follow-parent.sh
+13 -3
@@ -95,12 +95,12 @@ test_expect_success 'follow higher-level parent' "
95 "
96
97 test_expect_success 'follow deleted directory' "
98 - svn mv -m 'bye!' $svnrepo/glob/blob/hi $svnrepo/glob/blob/bye&&
98 + svn mv -m 'bye!' $svnrepo/glob/blob/hi $svnrepo/glob/blob/bye &&
99 svn rm -m 'remove glob' $svnrepo/glob &&
100 git-svn init -i glob $svnrepo/glob &&
101 git-svn fetch -i glob &&
102 - test \"\`git cat-file blob refs/remotes/glob~1:blob/bye\`\" = hi &&
103 - test -z \"\`git ls-tree -z refs/remotes/glob\`\"
102 + test \"\`git cat-file blob refs/remotes/glob:blob/bye\`\" = hi &&
103 + test \"\`git ls-tree refs/remotes/glob | wc -l \`\" -eq 1
104 "
105
106 # ref: r9270 of the Subversion repository: (http://svn.collab.net/repos/svn)
@@ -146,6 +146,16 @@ test_expect_success "track initial change if it was only made to parent" "
146 \"\`git rev-parse r9270-d~1\`\"
147 "
148
149 +test_expect_success "multi-fetch continues to work" "
150 + git-svn multi-fetch --follow-parent
151 + "
152 +
153 +test_expect_success "multi-fetch works off a 'clean' repository" "
154 + rm -r $GIT_DIR/svn $GIT_DIR/refs/remotes $GIT_DIR/logs &&
155 + mkdir $GIT_DIR/svn &&
156 + git-svn multi-fetch --follow-parent
157 + "
158 +
159 test_debug 'gitk --all &'
160
161 test_done