@matheusbsbs / matheus-bagliano / commits / e5a0b240fc
Fork 0

git-svn: correctly track revisions made to deleted branches

git-svn has never been able to handle deleted branches very well because svn_ra_get_log() is all-or-nothing, meaning that if the max revision passed to it does not contain the path we're tracking, we miss all the revisions in the repository. Branches fetched using --follow-parent still do this sub-optimally (will be fixed soon). --follow-parent will soon become the default, so we will assume that when using get_log(); We will also avoid tracking revprops for revisions with no path-related changes since otherwise we just end up pulling logs to paths we don't care about. Also added a test for this to t9104-git-svn-follow-parent.sh and correctly commit the log message in the preceeding test (which conflicted with a filename). Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Jan 25, 2007 at 15:44 UTC e5a0b240fc237af6165b728ae9c79288ef624d3b
2 files changed +34 -23
git-svn.perl
+24 -22
@@ -1100,6 +1100,11 @@ sub revisions_eq {
1100 sub find_parent_branch {
1101 my ($self, $paths, $rev) = @_;
1102 return undef unless $::_follow_parent;
1103 + unless (defined $paths) {
1104 + $self->ra->get_log([''], $rev, $rev, 0, 1, 1,
1105 + sub { $paths = $_[0] });
1106 + }
1107 + return undef unless defined $paths;
1108
1109 # look for a parent from another branch:
1110 my @b_path_components = split m#/#, $self->rel_path;
@@ -1146,11 +1151,11 @@ sub find_parent_branch {
1151 }
1152 my ($r0, $parent) = $gs->find_rev_before($r, 1);
1153 if ($::_follow_parent && (!defined $r0 || !defined $parent)) {
1149 - $gs->ra->get_log([$gs->{path}], 0, $r, 0, 1, 1, sub {
1150 - my ($paths, $rev) = @_;
1151 - my $log_entry = eval { $gs->do_fetch($paths, $rev) };
1152 - $gs->do_git_commit($log_entry) if $log_entry;
1153 - });
1154 + foreach (1 .. $r) {
1155 + if (my $log_entry = $gs->do_fetch(undef, $_)) {
1156 + $gs->do_git_commit($log_entry);
1157 + }
1158 + }
1159 ($r0, $parent) = $gs->last_rev_commit;
1160 }
1161 if (defined $r0 && defined $parent && $gs->revisions_eq($r0, $r)) {
@@ -1178,16 +1183,8 @@ sub find_parent_branch {
1183 }
1184 not_found:
1185 print STDERR "Branch parent for path: '/",
1181 - $self->rel_path, "' not found\n";
1182 - return undef unless $paths;
1183 - foreach my $x (sort keys %$paths) {
1184 - my $p = $paths->{$x};
1185 - print STDERR ' ', $p->action, ' ', $x;
1186 - if (my $cp_from = $p->copyfrom_path) {
1187 - print STDERR "(from $cp_from:", $p->copyfrom_rev, ')';
1188 - }
1189 - print STDERR "\n";
1190 - }
1186 + $self->rel_path, "' @ $rev not found\n";
1187 + print STDERR ' ', $_, "\n" foreach (sort keys %$paths);
1188 return undef;
1189 }
1190
@@ -1279,6 +1276,8 @@ sub make_log_entry {
1276 my ($self, $rev, $parents, $ed) = @_;
1277 my $untracked = $self->get_untracked($ed);
1278
1279 + return undef if ($ed->{nr} == 0 && scalar @$untracked == 0);
1280 +
1281 open my $un, '>>', "$self->{dir}/unhandled.log" or croak $!;
1282 print $un "r$rev\n" or croak $!;
1283 print $un $_, "\n" foreach @$untracked;
@@ -1296,10 +1295,6 @@ sub make_log_entry {
1295 }
1296 close $un or croak $!;
1297
1299 - delete $rp->{'svn:date'}; # this is the only revprop for r0
1300 - return undef if ($ed->{nr} == 0 && scalar @$untracked == 0 &&
1301 - scalar keys %$rp == 0);
1302 -
1298 $log_entry{date} = parse_svn_date($log_entry{date});
1299 $log_entry{author} = check_author($log_entry{author});
1300 $log_entry{log} .= "\n";
@@ -1317,18 +1312,26 @@ sub fetch {
1312 my $inc = 1000;
1313 my ($min, $max) = ($base, $head < $base + $inc ? $head : $base + $inc);
1314 my $err_handler = $SVN::Error::handler;
1320 - $SVN::Error::handler = \&skip_unknown_revs;
1315 + my $err;
1316 + $SVN::Error::handler = sub { ($err) = @_; skip_unknown_revs($err); } ;
1317 while (1) {
1318 my @revs;
1319 $self->ra->get_log([$self->{path}], $min, $max, 0, 1, 1, sub {
1320 my ($paths, $rev, $author, $date, $log) = @_;
1321 push @revs, [ $paths, $rev ] });
1322 + if (! @revs && $err) {
1323 + print STDERR "Branch probably deleted:\n ",
1324 + $err->expanded_message,
1325 + "\nWill attempt to follow revisions ",
1326 + "committed before the deletion\n";
1327 + @revs = map { [ undef, $_ ] } ($min .. $max);
1328 + }
1329 foreach (@revs) {
1330 if (my $log_entry = $self->do_fetch(@$_)) {
1331 $self->do_git_commit($log_entry, @parents);
1332 }
1333 }
1331 - last if $max >= $head;
1334 + last if $max >= $head || $err;
1335 $min = $max + 1;
1336 $max += $inc;
1337 $max = $head if ($max > $head);
@@ -2226,7 +2229,6 @@ sub dup {
2229 sub get_log {
2230 my ($self, @args) = @_;
2231 my $pool = SVN::Pool->new;
2229 - $args[4]-- if $args[4] && ! $::_follow_parent;
2232 splice(@args, 3, 1) if ($SVN::Core::VERSION le '1.2.0');
2233 my $ret = $self->SUPER::get_log(@args, $pool);
2234 $pool->clear;
t/t9104-git-svn-follow-parent.sh
+10 -1
@@ -85,7 +85,7 @@ test_expect_success 'follow higher-level parent' "
85 cd blob &&
86 echo hi > hi &&
87 svn add hi &&
88 - svn commit -m 'hi' &&
88 + svn commit -m 'hihi' &&
89 cd ..
90 svn mkdir -m 'new glob at top level' $svnrepo/glob &&
91 svn mv -m 'move blob down a level' $svnrepo/blob $svnrepo/glob/blob &&
@@ -93,6 +93,15 @@ test_expect_success 'follow higher-level parent' "
93 git-svn fetch -i blob --follow-parent
94 "
95
96 +test_expect_success 'follow deleted directory' "
97 + svn mv -m 'bye!' $svnrepo/glob/blob/hi $svnrepo/glob/blob/bye&&
98 + svn rm -m 'remove glob' $svnrepo/glob &&
99 + git-svn init -i glob $svnrepo/glob &&
100 + git-svn fetch -i glob &&
101 + test \"\`git cat-file blob refs/remotes/glob~1:blob/bye\`\" = hi &&
102 + test -z \"\`git ls-tree -z refs/remotes/glob\`\"
103 + "
104 +
105 test_debug 'gitk --all &'
106
107 test_done