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

git-svn: use do_switch for --follow-parent if the SVN library supports it

do_switch works with the SVN Perl bindings after r22312 in the Subversion trunk. Since no released version of SVN currently supports it; we'll just autodetect it and enable its usage when a user has a recent-enough version of SVN. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed Dec 8, 2006 at 02:20 UTC a552db3a64464f1b514b074fbc43aaf599106087
1 file changed +39 -7
git-svn.perl
+39 -7
@@ -72,7 +72,7 @@ my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
72 $_username, $_config_dir, $_no_auth_cache, $_xfer_delta,
73 $_pager, $_color);
74 my (@_branch_from, %tree_map, %users, %rusers, %equiv);
75 -my ($_svn_co_url_revs, $_svn_pg_peg_revs);
75 +my ($_svn_co_url_revs, $_svn_pg_peg_revs, $_svn_can_do_switch);
76 my @repo_path_split_cache;
77
78 my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
@@ -2877,6 +2877,24 @@ sub libsvn_connect {
2877 return $ra;
2878 }
2879
2880 +sub libsvn_can_do_switch {
2881 + unless (defined $_svn_can_do_switch) {
2882 + my $pool = SVN::Pool->new;
2883 + my $rep = eval {
2884 + $SVN->do_switch(1, '', 0, $SVN->{url},
2885 + SVN::Delta::Editor->new, $pool);
2886 + };
2887 + if ($@) {
2888 + $_svn_can_do_switch = 0;
2889 + } else {
2890 + $rep->abort_report($pool);
2891 + $_svn_can_do_switch = 1;
2892 + }
2893 + $pool->clear;
2894 + }
2895 + $_svn_can_do_switch;
2896 +}
2897 +
2898 sub libsvn_dup_ra {
2899 my ($ra) = @_;
2900 SVN::Ra->new(map { $_ => $ra->{$_} } qw/config url
@@ -3198,12 +3216,26 @@ sub libsvn_find_parent_branch {
3216 unlink $GIT_SVN_INDEX;
3217 print STDERR "Found branch parent: ($GIT_SVN) $parent\n";
3218 sys(qw/git-read-tree/, $parent);
3201 - # I can't seem to get do_switch() to work correctly with
3202 - # the SWIG interface (TypeError when passing switch_url...),
3203 - # so we'll unconditionally bypass the delta interface here
3204 - # for now
3205 - return libsvn_fetch_full($parent, $paths, $rev,
3206 - $author, $date, $msg);
3219 + unless (libsvn_can_do_switch()) {
3220 + return libsvn_fetch_full($parent, $paths, $rev,
3221 + $author, $date, $msg);
3222 + }
3223 + # do_switch works with svn/trunk >= r22312, but that is not
3224 + # included with SVN 1.4.2 (the latest version at the moment),
3225 + # so we can't rely on it.
3226 + my $ra = libsvn_connect("$url/$branch_from");
3227 + my $ed = SVN::Git::Fetcher->new({c => $parent, q => $_q});
3228 + my $pool = SVN::Pool->new;
3229 + my $reporter = $ra->do_switch($rev, '', 1, $SVN->{url},
3230 + $ed, $pool);
3231 + my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
3232 + $reporter->set_path('', $r0, 0, @lock, $pool);
3233 + $reporter->finish_report($pool);
3234 + $pool->clear;
3235 + unless ($ed->{git_commit_ok}) {
3236 + die "SVN connection failed somewhere...\n";
3237 + }
3238 + return libsvn_log_entry($rev, $author, $date, $msg, [$parent]);
3239 }
3240 print STDERR "Nope, branch point not imported or unknown\n";
3241 return undef;