@matheusbsbs / matheus-bagliano / commits / 2b27f6c884
Fork 0

git-svn: correctly handle do_{switch,update} in deep directories

The do_update or do_switch functions in SVN only allow for a single path component; so 'path/to/deep/dir' would be interpreted as 'path'. SVN 1.4.x has a reparent function that can let us change the session to use a higher-level root of the repository, so we can use that for do_switch (which still doesn't seem to work in SVN 1.4.3 (a fix was attempted, but they missed the rest of the typemap changes needed in trunk...)). On the do_update side, we can use set_path on higher level directories and set them to a newer revision so they don't get updated. We can't do this with do_switch, either, because the relative path we're tracking can change (directory moving into a child of itself). Because of these changes, we need to double check that our Fetch editor is correctly performing stripping on any prefixed paths from update, otherwise we'll just die() because that would be a bug. Added a test case which helped me notice and fix problems with do_switch, too. Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Jan 28, 2007 at 04:59 UTC 2b27f6c8847ebee631e7ad17ac9986e461d7674b
2 files changed +69 -8
git-svn.perl
+38 -8
@@ -1153,7 +1153,7 @@ sub find_parent_branch {
1153 if ($self->ra->can_do_switch) {
1154 print STDERR "Following parent with do_switch\n";
1155 # do_switch works with svn/trunk >= r22312, but that
1156 - # is not included with SVN 1.4.2 (the latest version
1156 + # is not included with SVN 1.4.3 (the latest version
1157 # at the moment), so we can't rely on it
1158 $self->{last_commit} = $parent;
1159 $ed = SVN::Git::Fetcher->new($self);
@@ -1621,7 +1621,10 @@ sub open_directory {
1621
1622 sub git_path {
1623 my ($self, $path) = @_;
1624 - $path =~ s!$self->{path_strip}!! if $self->{path_strip};
1624 + if ($self->{path_strip}) {
1625 + $path =~ s!$self->{path_strip}!! or
1626 + die "Failed to strip path '$path' ($self->{path_strip})\n";
1627 + }
1628 $path;
1629 }
1630
@@ -2249,25 +2252,52 @@ sub gs_do_update {
2252 my ($self, $rev_a, $rev_b, $path, $recurse, $editor) = @_;
2253 my $pool = SVN::Pool->new;
2254 $editor->set_path_strip($path);
2252 - my $reporter = $self->do_update($rev_b, $path, $recurse,
2253 - $editor, $pool);
2255 + my (@pc) = split m#/#, $path;
2256 + my $reporter = $self->do_update($rev_b, (@pc ? shift @pc : ''),
2257 + $recurse, $editor, $pool);
2258 my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
2259 +
2260 + # Since we can't rely on svn_ra_reparent being available, we'll
2261 + # just have to do some magic with set_path to make it so
2262 + # we only want a partial path.
2263 + my $sp = '';
2264 + my $final = join('/', @pc);
2265 + while (@pc) {
2266 + $reporter->set_path($sp, $rev_b, 0, @lock, $pool);
2267 + $sp .= '/' if length $sp;
2268 + $sp .= shift @pc;
2269 + }
2270 + die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
2271 +
2272 my $new = ($rev_a == $rev_b);
2256 - $reporter->set_path('', $rev_a, $new, @lock, $pool);
2273 + $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
2274 +
2275 $reporter->finish_report($pool);
2276 $pool->clear;
2277 $editor->{git_commit_ok};
2278 }
2279
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 {
2283 my ($self, $rev_a, $rev_b, $path, $recurse, $url_b, $editor) = @_;
2284 my $pool = SVN::Pool->new;
2265 - $editor->set_path_strip($path);
2266 - my $reporter = $self->do_switch($rev_b, $path, $recurse,
2267 - $url_b, $editor, $pool);
2285 +
2286 + my $full_url = $self->{url};
2287 + my $old_url = $full_url;
2288 + $full_url .= "/$path" if length $path;
2289 + SVN::_Ra::svn_ra_reparent($self->{session}, $full_url, $pool);
2290 + $self->{url} = $full_url;
2291 +
2292 + my $reporter = $self->do_switch($rev_b, '',
2293 + $recurse, $url_b, $editor, $pool);
2294 my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
2295 $reporter->set_path('', $rev_a, 0, @lock, $pool);
2296 $reporter->finish_report($pool);
2297 +
2298 + SVN::_Ra::svn_ra_reparent($self->{session}, $old_url, $pool);
2299 + $self->{url} = $old_url;
2300 +
2301 $pool->clear;
2302 $editor->{git_commit_ok};
2303 }
t/t9104-git-svn-follow-parent.sh
+31
@@ -101,6 +101,37 @@ test_expect_success 'follow deleted directory' "
101 test -z \"\`git ls-tree -z refs/remotes/glob\`\"
102 "
103
104 +# ref: r9270 of the Subversion repository: (http://svn.collab.net/repos/svn)
105 +# in trunk/subversion/bindings/swig/perl
106 +test_expect_success '' "
107 + mkdir -p import/trunk/subversion/bindings/swig/perl/t &&
108 + for i in a b c ; do \
109 + echo \$i > import/trunk/subversion/bindings/swig/perl/\$i.pm &&
110 + echo _\$i > import/trunk/subversion/bindings/swig/perl/t/\$i.t; \
111 + done &&
112 + echo 'bad delete test' > \
113 + import/trunk/subversion/bindings/swig/perl/t/larger-parent &&
114 + echo 'bad delete test 2' > \
115 + import/trunk/subversion/bindings/swig/perl/another-larger &&
116 + cd import &&
117 + svn import -m 'r9270 test' . $svnrepo/r9270 &&
118 + cd .. &&
119 + svn co $svnrepo/r9270/trunk/subversion/bindings/swig/perl r9270 &&
120 + cd r9270 &&
121 + svn mkdir native &&
122 + svn mv t native/t &&
123 + for i in a b c; do svn mv \$i.pm native/\$i.pm; done &&
124 + echo z >> native/t/c.t &&
125 + svn commit -m 'reorg test' &&
126 + cd .. &&
127 + git-svn init -i r9270-t \
128 + $svnrepo/r9270/trunk/subversion/bindings/swig/perl/native/t &&
129 + git-svn fetch -i r9270-t --follow-parent &&
130 + test \`git rev-list r9270-t | wc -l\` -eq 2 &&
131 + test \"\`git ls-tree --name-only r9270-t~1\`\" = \
132 + \"\`git ls-tree --name-only r9270-t\`\"
133 + "
134 +
135 test_debug 'gitk --all &'
136
137 test_done