@matheusbsbs / matheus-bagliano / commits / 8b8fc06824
Fork 0

git-svn: --follow-parent works with svn-remotes multiple branches

Bugs fixed: * We didn't allow manually (not using git-svn) init-ed remotes/fetch refspecs to be used before. It works now because that's what I did in this test. git-svn init should offer more control in the future. * correctly strip paths in the delta editor when using do_switch(). * Make the -i / GIT_SVN_ID option work correctly when doing fetch on a multi-ref svn-remote Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Jan 22, 2007 at 11:44 UTC 8b8fc06824cde2b314807e5e3a20e0adfd948cda
2 files changed +45 -17
git-svn.perl
+32 -17
@@ -14,7 +14,8 @@ $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
14 $VERSION = '@@GIT_VERSION@@';
15
16 $ENV{GIT_DIR} ||= '.git';
17 -$Git::SVN::default_repo_id = $ENV{GIT_SVN_ID} || 'git-svn';
17 +$Git::SVN::default_repo_id = 'git-svn';
18 +$Git::SVN::default_ref_id = $ENV{GIT_SVN_ID} || 'git-svn';
19
20 my $LC_ALL = $ENV{LC_ALL};
21 $Git::SVN::Log::TZ = $ENV{TZ};
@@ -158,7 +159,7 @@ my $rv = GetOptions(%opts, 'help|H|h' => \$_help,
159 'version|V' => \$_version,
160 'minimize-connections' =>
161 \$Git::SVN::Migration::_minimize,
161 - 'id|i=s' => \$Git::SVN::default_repo_id);
162 + 'id|i=s' => \$Git::SVN::default_ref_id);
163 exit 1 if (!$rv && $cmd ne 'log');
164
165 usage(0) if $_help;
@@ -686,7 +687,7 @@ sub tz_to_s_offset {
687 package Git::SVN;
688 use strict;
689 use warnings;
689 -use vars qw/$default_repo_id/;
690 +use vars qw/$default_repo_id $default_ref_id/;
691 use Carp qw/croak/;
692 use File::Path qw/mkpath/;
693 use IPC::Open3;
@@ -704,7 +705,7 @@ BEGIN {
705
706 sub read_all_remotes {
707 my $r = {};
707 - foreach (grep { s/^svn-remote\.// } command(qw/repo-config -l/)) {
708 + foreach (grep { s/^svn-remote\.// } command(qw/config -l/)) {
709 if (m!^(.+)\.fetch=\s*(.*)\s*:\s*refs/remotes/(.+)\s*$!) {
710 $r->{$1}->{fetch}->{$2} = $3;
711 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
@@ -724,7 +725,6 @@ sub sanitize_remote_name {
725 sub init {
726 my ($class, $url, $path, $repo_id, $ref_id) = @_;
727 my $self = _new($class, $repo_id, $ref_id, $path);
727 - mkpath([$self->{dir}]);
728 if (defined $url) {
729 $url =~ s!/+$!!; # strip trailing slash
730 my $orig_url = eval {
@@ -745,10 +745,6 @@ sub init {
745 "$path:".$self->refname);
746 }
747 $self->{url} = $url;
748 - unless (-f $self->{db_path}) {
749 - open my $fh, '>>', $self->{db_path} or croak $!;
750 - close $fh or croak $!;
751 - }
748 $self;
749 }
750
@@ -777,6 +773,14 @@ sub new {
773 }
774 }
775 my $self = _new($class, $repo_id, $ref_id, $path);
776 + if (!defined $self->{path} || !length $self->{path}) {
777 + my $fetch = command_oneline('config', '--get',
778 + "svn-remote.$repo_id.fetch",
779 + ":refs/remotes/$ref_id\$") or
780 + die "Failed to read \"svn-remote.$repo_id.fetch\" ",
781 + "\":refs/remotes/$ref_id\$\" in config\n";
782 + ($self->{path}, undef) = split(/\s*:\s*/, $fetch);
783 + }
784 $self->{url} = command_oneline('config', '--get',
785 "svn-remote.$repo_id.url") or
786 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
@@ -1064,6 +1068,7 @@ sub find_parent_branch {
1068 command_noisy('read-tree', $parent);
1069 my $ed;
1070 if ($self->ra->can_do_switch) {
1071 + print STDERR "Following parent with do_switch\n";
1072 # do_switch works with svn/trunk >= r22312, but that
1073 # is not included with SVN 1.4.2 (the latest version
1074 # at the moment), so we can't rely on it
@@ -1073,6 +1078,7 @@ sub find_parent_branch {
1078 $self->full_url, $ed)
1079 or die "SVN connection failed somewhere...\n";
1080 } else {
1081 + print STDERR "Following parent with do_update\n";
1082 $ed = SVN::Git::Fetcher->new($self);
1083 $self->ra->gs_do_update($rev, $rev, $self->{path},
1084 1, $ed)
@@ -1209,7 +1215,7 @@ sub fetch {
1215 $SVN::Error::handler = \&skip_unknown_revs;
1216 while (1) {
1217 my @revs;
1212 - $self->ra->get_log([''], $min, $max, 0, 1, 1, sub {
1218 + $self->ra->get_log([$self->{path}], $min, $max, 0, 1, 1, sub {
1219 my ($paths, $rev, $author, $date, $log) = @_;
1220 push @revs, [ $paths, $rev ] });
1221 foreach (@revs) {
@@ -1341,11 +1347,16 @@ sub _new {
1347 $repo_id = $Git::SVN::default_repo_id;
1348 }
1349 unless (defined $ref_id && length $ref_id) {
1344 - $_[2] = $ref_id = $repo_id;
1350 + $_[2] = $ref_id = $Git::SVN::default_ref_id;
1351 }
1352 $_[1] = $repo_id = sanitize_remote_name($repo_id);
1353 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
1354 $_[3] = $path = '' unless (defined $path);
1355 + mkpath([$dir]);
1356 + unless (-f "$dir/.rev_db") {
1357 + open my $fh, '>>', "$dir/.rev_db" or croak $!;
1358 + close $fh or croak $!;
1359 + }
1360 bless { ref_id => $ref_id, dir => $dir, index => "$dir/index",
1361 path => $path,
1362 db_path => "$dir/.rev_db", repo_id => $repo_id }, $class;
@@ -1526,9 +1537,6 @@ sub new {
1537 my $self = SVN::Delta::Editor->new;
1538 bless $self, $class;
1539 $self->{c} = $git_svn->{last_commit} if exists $git_svn->{last_commit};
1529 - if (length $git_svn->{path}) {
1530 - $self->{path_strip} = qr/\Q$git_svn->{path}\E\/?/;
1531 - }
1540 $self->{empty} = {};
1541 $self->{dir_prop} = {};
1542 $self->{file_prop} = {};
@@ -1540,6 +1548,11 @@ sub new {
1548 $self;
1549 }
1550
1551 +sub set_path_strip {
1552 + my ($self, $path) = @_;
1553 + $self->{path_strip} = qr/^\Q$path\E\/?/;
1554 +}
1555 +
1556 sub open_root {
1557 { path => '' };
1558 }
@@ -2128,6 +2141,7 @@ sub uuid {
2141 sub gs_do_update {
2142 my ($self, $rev_a, $rev_b, $path, $recurse, $editor) = @_;
2143 my $pool = SVN::Pool->new;
2144 + $editor->set_path_strip($path);
2145 my $reporter = $self->do_update($rev_b, $path, $recurse,
2146 $editor, $pool);
2147 my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
@@ -2141,10 +2155,11 @@ sub gs_do_update {
2155 sub gs_do_switch {
2156 my ($self, $rev_a, $rev_b, $path, $recurse, $url_b, $editor) = @_;
2157 my $pool = SVN::Pool->new;
2158 + $editor->set_path_strip($path);
2159 my $reporter = $self->do_switch($rev_b, $path, $recurse,
2160 $url_b, $editor, $pool);
2161 my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
2147 - $reporter->set_path($path, $rev_a, 0, @lock, $pool);
2162 + $reporter->set_path('', $rev_a, 0, @lock, $pool);
2163 $reporter->finish_report($pool);
2164 $pool->clear;
2165 $editor->{git_commit_ok};
@@ -2674,12 +2689,12 @@ sub minimize_connections {
2689
2690 my $old_fetch = quotemeta("$x->{old_path}:".
2691 "refs/remotes/$x->{ref_id}");
2677 - command_noisy(qw/repo-config --unset/,
2692 + command_noisy(qw/config --unset/,
2693 "$pfx.fetch", '^'. $old_fetch . '$');
2694 delete $r->{$x->{old_repo_id}}->
2695 {fetch}->{$x->{old_path}};
2696 if (!keys %{$r->{$x->{old_repo_id}}->{fetch}}) {
2682 - command_noisy(qw/repo-config --unset/,
2697 + command_noisy(qw/config --unset/,
2698 "$pfx.url");
2699 push @emptied, $x->{old_repo_id}
2700 }
t/t9104-git-svn-follow-parent.sh
+13
@@ -36,6 +36,19 @@ test_expect_success 'init and fetch --follow-parent a moved directory' "
36 sed -n -e '3p'\`\" = goodbye
37 "
38
39 +test_expect_success 'init and fetch from one svn-remote' "
40 + git-repo-config svn-remote.git-svn.url $svnrepo &&
41 + git-repo-config --add svn-remote.git-svn.fetch \
42 + trunk:refs/remotes/svn/trunk &&
43 + git-repo-config --add svn-remote.git-svn.fetch \
44 + thunk:refs/remotes/svn/thunk &&
45 + git-svn fetch --follow-parent -i svn/thunk &&
46 + test \"\`git-rev-parse --verify refs/remotes/svn/trunk\`\" \
47 + = \"\`git-rev-parse --verify refs/remotes/svn/thunk~1\`\" &&
48 + test \"\`git-cat-file blob refs/remotes/svn/thunk:readme |\
49 + sed -n -e '3p'\`\" = goodbye
50 + "
51 +
52 test_debug 'gitk --all &'
53
54 test_done