@matheusbsbs / matheus-bagliano / commits / 9ff74e95da
Fork 0

Don't checkout the full tree if avoidable

In most cases of branching, the tree is copied unmodified from the trunk to the branch. When that is done, we can simply start with the parent's index and apply the changes on the branch as usual. [ew: rewritten from Steven's original to use SVN::Client instead of the command-line svn client. Since SVN::Client connects separately, we'll share our authentication providers array between our usages of SVN::Client and SVN::Ra, too. Bypassing the high-level SVN::Client library can avoid this, but the code will be much more complex. Regardless, any implementation of this seems to require restarting a connection to the remote server. Also of note is that SVN 1.4 and later allows a more efficient diff_summary to be done instead of a full diff, but since this code is only to support SVN < 1.4.4, we'll ignore it for now.] Signed-off-by: Steven Walter <stevenrwalter@gmail.com> Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Steven Walter committed Sep 28, 2007 at 13:24 UTC 9ff74e95da5605778bdc7567ae63d70c96e6bed4
1 file changed +48 -16
git-svn.perl
+48 -16
@@ -1847,6 +1847,16 @@ sub find_parent_branch {
1847 $gs->ra->gs_do_switch($r0, $rev, $gs,
1848 $self->full_url, $ed)
1849 or die "SVN connection failed somewhere...\n";
1850 + } elsif ($self->ra->trees_match($new_url, $r0,
1851 + $self->full_url, $rev)) {
1852 + print STDERR "Trees match:\n",
1853 + " $new_url\@$r0\n",
1854 + " ${\$self->full_url}\@$rev\n",
1855 + "Following parent with no changes\n";
1856 + $self->tmp_index_do(sub {
1857 + command_noisy('read-tree', $parent);
1858 + });
1859 + $self->{last_commit} = $parent;
1860 } else {
1861 print STDERR "Following parent with do_update\n";
1862 $ed = SVN::Git::Fetcher->new($self);
@@ -3027,28 +3037,32 @@ BEGIN {
3037 }
3038 }
3039
3040 +sub _auth_providers () {
3041 + [
3042 + SVN::Client::get_simple_provider(),
3043 + SVN::Client::get_ssl_server_trust_file_provider(),
3044 + SVN::Client::get_simple_prompt_provider(
3045 + \&Git::SVN::Prompt::simple, 2),
3046 + SVN::Client::get_ssl_client_cert_file_provider(),
3047 + SVN::Client::get_ssl_client_cert_prompt_provider(
3048 + \&Git::SVN::Prompt::ssl_client_cert, 2),
3049 + SVN::Client::get_ssl_client_cert_pw_prompt_provider(
3050 + \&Git::SVN::Prompt::ssl_client_cert_pw, 2),
3051 + SVN::Client::get_username_provider(),
3052 + SVN::Client::get_ssl_server_trust_prompt_provider(
3053 + \&Git::SVN::Prompt::ssl_server_trust),
3054 + SVN::Client::get_username_prompt_provider(
3055 + \&Git::SVN::Prompt::username, 2)
3056 + ]
3057 +}
3058 +
3059 sub new {
3060 my ($class, $url) = @_;
3061 $url =~ s!/+$!!;
3062 return $RA if ($RA && $RA->{url} eq $url);
3063
3064 SVN::_Core::svn_config_ensure($config_dir, undef);
3036 - my ($baton, $callbacks) = SVN::Core::auth_open_helper([
3037 - SVN::Client::get_simple_provider(),
3038 - SVN::Client::get_ssl_server_trust_file_provider(),
3039 - SVN::Client::get_simple_prompt_provider(
3040 - \&Git::SVN::Prompt::simple, 2),
3041 - SVN::Client::get_ssl_client_cert_file_provider(),
3042 - SVN::Client::get_ssl_client_cert_prompt_provider(
3043 - \&Git::SVN::Prompt::ssl_client_cert, 2),
3044 - SVN::Client::get_ssl_client_cert_pw_prompt_provider(
3045 - \&Git::SVN::Prompt::ssl_client_cert_pw, 2),
3046 - SVN::Client::get_username_provider(),
3047 - SVN::Client::get_ssl_server_trust_prompt_provider(
3048 - \&Git::SVN::Prompt::ssl_server_trust),
3049 - SVN::Client::get_username_prompt_provider(
3050 - \&Git::SVN::Prompt::username, 2),
3051 - ]);
3065 + my ($baton, $callbacks) = SVN::Core::auth_open_helper(_auth_providers);
3066 my $config = SVN::Core::config_get_config($config_dir);
3067 $RA = undef;
3068 my $self = SVN::Ra->new(url => $url, auth => $baton,
@@ -3112,6 +3126,24 @@ sub get_log {
3126 $ret;
3127 }
3128
3129 +sub trees_match {
3130 + my ($self, $url1, $rev1, $url2, $rev2) = @_;
3131 + my $ctx = SVN::Client->new(auth => _auth_providers);
3132 + my $out = IO::File->new_tmpfile;
3133 +
3134 + # older SVN (1.1.x) doesn't take $pool as the last parameter for
3135 + # $ctx->diff(), so we'll create a default one
3136 + my $pool = SVN::Pool->new_default_sub;
3137 +
3138 + $ra_invalid = 1; # this will open a new SVN::Ra connection to $url1
3139 + $ctx->diff([], $url1, $rev1, $url2, $rev2, 1, 1, 0, $out, $out);
3140 + $out->flush;
3141 + my $ret = (($out->stat)[7] == 0);
3142 + close $out or croak $!;
3143 +
3144 + $ret;
3145 +}
3146 +
3147 sub get_commit_editor {
3148 my ($self, $log, $cb, $pool) = @_;
3149 my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef, 0) : ();