git-svn: --follow-parent now works on sub-directories of larger branches
This means that tracking the path of: /another-larger/trunk/thunk/bump/thud inside a repository would follow: /larger-parent/trunk/thunk/bump/thud even if the svn log output looks like this: -------------------------------------------- Changed paths: A /another-larger (from /larger-parent:5) -------------------------------------------- Note: the usage of get_log() in git-svn still makes a an assumption that shouldn't be made with regard to revisions existing for a particular path. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jan 24, 2007 at 02:16 UTC
7f578c55af80e9346135004bd47099cbb451f859
2 files changed
+40
-8
git-svn.perl
+23
-8
@@ -1102,9 +1102,21 @@ sub find_parent_branch {
1102
return undef unless $::_follow_parent;
1103
1104
# look for a parent from another branch:
1105
- my $abs_path = '/'.$self->rel_path;
1106
- my $i = $paths->{$abs_path} or goto not_found;
1105
+ my @b_path_components = split m#/#, $self->rel_path;
1106
+ my @a_path_components;
1107
+ my $i;
1108
+ while (@b_path_components) {
1109
+ $i = $paths->{'/'.join('/', @b_path_components)};
1110
+ last if $i;
1111
+ unshift(@a_path_components, pop(@b_path_components));
1112
+ }
1113
+ goto not_found unless defined $i;
1114
my $branch_from = $i->copyfrom_path or goto not_found;
1115
+ if (@a_path_components) {
1116
+ print STDERR "branch_from: $branch_from => ";
1117
+ $branch_from .= '/'.join('/', @a_path_components);
1118
+ print STDERR $branch_from, "\n";
1119
+ }
1120
my $r = $i->copyfrom_rev;
1121
my $repos_root = $self->ra->{repos_root};
1122
my $url = $self->ra->{url};
@@ -1134,10 +1146,11 @@ sub find_parent_branch {
1146
}
1147
my ($r0, $parent) = $gs->find_rev_before($r, 1);
1148
if ($::_follow_parent && (!defined $r0 || !defined $parent)) {
1137
- foreach (0 .. $r) {
1138
- my $log_entry = eval { $gs->do_fetch(undef, $_) };
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;
1140
- }
1153
+ });
1154
($r0, $parent) = $gs->last_rev_commit;
1155
}
1156
if (defined $r0 && defined $parent && $gs->revisions_eq($r0, $r)) {
@@ -1164,10 +1177,12 @@ sub find_parent_branch {
1177
return $self->make_log_entry($rev, [$parent], $ed);
1178
}
1179
not_found:
1167
- print STDERR "Branch parent for path: '$abs_path' not found\n";
1180
+ print STDERR "Branch parent for path: '/",
1181
+ $self->rel_path, "' not found\n";
1182
return undef unless $paths;
1169
- foreach my $p (sort keys %$paths) {
1170
- print STDERR ' ', $p->action, ' ', $p;
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
}
t/t9104-git-svn-follow-parent.sh
+17
@@ -61,6 +61,23 @@ test_expect_success 'follow deleted parent' "
61
= \"\`git rev-parse svn/trunk\`\"
62
"
63
64
+test_expect_success 'follow larger parent' "
65
+ mkdir -p import/trunk/thunk/bump/thud &&
66
+ echo hi > import/trunk/thunk/bump/thud/file &&
67
+ svn import -m 'import a larger parent' import $svnrepo/larger-parent &&
68
+ svn cp -m 'hi' $svnrepo/larger-parent $svnrepo/another-larger &&
69
+ git-svn init -i larger $svnrepo/another-larger/trunk/thunk/bump/thud &&
70
+ git-svn fetch -i larger --follow-parent &&
71
+ git-rev-parse --verify refs/remotes/larger &&
72
+ git-rev-parse --verify \
73
+ refs/remotes/larger-parent/trunk/thunk/bump/thud &&
74
+ test \"\`git-merge-base \
75
+ refs/remotes/larger-parent/trunk/thunk/bump/thud \
76
+ refs/remotes/larger\`\" = \
77
+ \"\`git-rev-parse refs/remotes/larger\`\"
78
+ true
79
+ "
80
+
81
test_debug 'gitk --all &'
82
83
test_done