git-svn: handle multi-init without --trunk, UseSvmProps fixes
multi-init did not write a svn-remote.<remote>.url config entry without a --trunk argument. Also, The svm:mirror property is used by SVN::Mirror to track the path of the repository that we are mirroring. We need to append that to the source (which is (presumably) just the URL of the repository root). Lastly, we now look harder for svm:(source|mirror|uuid) properties in sub and parent directories. Since our relative path could be tweaked. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Feb 13, 2007 at 00:38 UTC
db03cd24a155a727349a47ce0e5ba3f4c4032cb8
1 file changed
+83
-33
git-svn.perl
+83
-33
@@ -367,8 +367,7 @@ sub cmd_multi_init {
367
sub cmd_multi_fetch {
368
my $remotes = Git::SVN::read_all_remotes();
369
foreach my $repo_id (sort keys %$remotes) {
370
- if ($remotes->{$repo_id}->{url} &&
371
- $remotes->{$repo_id}->{fetch}) {
370
+ if ($remotes->{$repo_id}->{url}) {
371
Git::SVN::fetch_all($repo_id, $remotes);
372
}
373
}
@@ -483,6 +482,17 @@ sub complete_url_ls_init {
482
$gs = Git::SVN->init($url, $path, undef, $ref, 1);
483
}
484
if ($gs) {
485
+ my $k = "svn-remote.$gs->{repo_id}.url";
486
+ my $orig_url = eval {
487
+ command_oneline(qw/config --get/, $k)
488
+ };
489
+ if ($orig_url && ($orig_url ne $gs->{url})) {
490
+ die "$k already set: $orig_url\n",
491
+ "wanted to set to: $gs->{url}\n";
492
+ }
493
+ unless ($orig_url) {
494
+ command_oneline('config', $k, $gs->{url});
495
+ }
496
$remote_id = $gs->{repo_id};
497
last;
498
}
@@ -751,13 +761,15 @@ sub fetch_all {
761
}
762
}
763
754
- foreach my $p (sort keys %$fetch) {
755
- my $gs = Git::SVN->new($fetch->{$p}, $repo_id, $p);
756
- my $lr = $gs->rev_db_max;
757
- if (defined $lr) {
758
- $base = $lr if ($lr < $base);
764
+ if ($fetch) {
765
+ foreach my $p (sort keys %$fetch) {
766
+ my $gs = Git::SVN->new($fetch->{$p}, $repo_id, $p);
767
+ my $lr = $gs->rev_db_max;
768
+ if (defined $lr) {
769
+ $base = $lr if ($lr < $base);
770
+ }
771
+ push @gs, $gs;
772
}
760
- push @gs, $gs;
773
}
774
$ra->gs_fetch_loop_common($base, $head, \@gs, \@globs);
775
}
@@ -974,35 +986,69 @@ sub svm {
986
987
sub _set_svm_vars {
988
my ($self, $ra) = @_;
989
+ return $ra if $self->svm;
990
+
991
+ my @err = ( "useSvmProps set, but failed to read SVM properties\n",
992
+ "(svm:source, svm:mirror, svm:mirror) ",
993
+ "from the following URLs:\n" );
994
+ sub read_svm_props {
995
+ my ($self, $props) = @_;
996
+ my $src = $props->{'svm:source'};
997
+ my $mirror = $props->{'svm:mirror'};
998
+ my $uuid = $props->{'svm:uuid'};
999
+ return undef if (!$src || !$mirror || !$uuid);
1000
978
- return $ra if ($self->svm);
979
-
980
- # nope, make sure we're connected to the repository root:
981
- if ($ra->{repos_root} ne $self->{url}) {
982
- $ra = Git::SVN::Ra->new($ra->{repos_root});
983
- }
984
- my $r = $ra->get_latest_revnum;
985
- my ($props) = ($ra->get_dir('', $r))[2];
986
- if (my $src = $props->{'svm:source'}) {
987
- my $section = "svn-remote.$self->{repo_id}";
1001
+ chomp($src, $mirror, $uuid);
1002
1003
+ $uuid =~ m{^[0-9a-f\-]{30,}$}
1004
+ or die "doesn't look right - svm:uuid is '$uuid'\n";
1005
# don't know what a '!' is there for, also the
1006
# username is of no interest
991
- $src =~ s{!$}{};
1007
+ $src =~ s{/?!$}{$mirror};
1008
+ $src =~ s{/+$}{}; # no trailing slashes please
1009
$src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
993
- tmp_config('--add', "$section.svm-source", $src);
1010
995
- my $uuid = $props->{'svm:uuid'};
996
- $uuid =~ m{^[0-9a-f\-]{30,}$}
997
- or die "doesn't look right - svm:uuid is '$uuid'\n";
1011
+ my $section = "svn-remote.$self->{repo_id}";
1012
+ tmp_config('--add', "$section.svm-source", $src);
1013
tmp_config('--add', "$section.svm-uuid", $uuid);
999
-
1014
$self->{svm} = { source => $src , uuid => $uuid };
1015
+ return 1;
1016
}
1002
- if ($ra->{repos_root} ne $self->{url}) {
1003
- $ra = Git::SVN::Ra->new($self->{url});
1017
+
1018
+ my $r = $ra->get_latest_revnum;
1019
+ my $path = $self->{path};
1020
+ my @tried_a = ($path);
1021
+ while (length $path) {
1022
+ if ($self->read_svm_props(($ra->get_dir($path, $r))[2])) {
1023
+ return $ra;
1024
+ }
1025
+ $path =~ s#/?[^/]+$## && push @tried_a, $path;
1026
}
1005
- $ra;
1027
+ if ($self->read_svm_props(($ra->get_dir('', $r))[2])) {
1028
+ return $ra;
1029
+ }
1030
+
1031
+ if ($ra->{repos_root} eq $self->{url}) {
1032
+ die @err, map { " $self->{url}/$_\n" } @tried_a, "\n";
1033
+ }
1034
+
1035
+ # nope, make sure we're connected to the repository root:
1036
+ my $ok;
1037
+ my @tried_b;
1038
+ $path = $ra->{svn_path};
1039
+ $path =~ s#/?[^/]+$##; # we already tried this one above
1040
+ $ra = Git::SVN::Ra->new($ra->{repos_root});
1041
+ while (length $path) {
1042
+ $ok = $self->read_svm_props(($ra->get_dir($path, $r))[2]);
1043
+ last if $ok;
1044
+ $path =~ s#/?[^/]+$## && push @tried_b, $path;
1045
+ }
1046
+ $ok = $self->read_svm_props(($ra->get_dir('', $r))[2]) unless $ok;
1047
+ if (!$ok) {
1048
+ die @err, map { " $self->{url}/$_\n" } @tried_a, "\n",
1049
+ map { " $ra->{url}/$_\n" } @tried_b, "\n"
1050
+ }
1051
+ Git::SVN::Ra->new($self->{url});
1052
}
1053
1054
# this allows us to memoize our SVN::Ra UUID locally and avoid a
@@ -1228,11 +1274,9 @@ sub do_git_commit {
1274
croak "$log_entry->{revision} = $c already exists! ",
1275
"Why are we refetching it?\n";
1276
}
1231
- my $author = $log_entry->{author};
1232
- my ($name, $email) = (defined $::users{$author} ? @{$::users{$author}}
1233
- : ($author, "$author\@".$self->ra->get_uuid));
1234
- $ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;
1235
- $ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;
1277
+ $ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $log_entry->{name};
1278
+ $ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} =
1279
+ $log_entry->{email};
1280
$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_entry->{date};
1281
1282
my $tree = $log_entry->{tree};
@@ -1522,8 +1566,10 @@ sub make_log_entry {
1566
close $un or croak $!;
1567
1568
$log_entry{date} = parse_svn_date($log_entry{date});
1525
- $log_entry{author} = check_author($log_entry{author});
1569
$log_entry{log} .= "\n";
1570
+ my $author = $log_entry{author} = check_author($log_entry{author});
1571
+ my ($name, $email) = defined $::users{$author} ? @{$::users{$author}}
1572
+ : ($author, undef);
1573
if (defined $headrev && $self->use_svm_props) {
1574
my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d+)$};
1575
if ($uuid ne $self->{svm}->{uuid}) {
@@ -1535,10 +1581,14 @@ sub make_log_entry {
1581
$full_url .= "/$self->{path}" if length $self->{path};
1582
$log_entry{metadata} = "$full_url\@$r $uuid";
1583
$log_entry{svm_revision} = $r;
1584
+ $email ||= "$author\@$uuid"
1585
} else {
1586
$log_entry{metadata} = $self->full_url . "\@$rev " .
1587
$self->ra->get_uuid;
1588
+ $email ||= "$author\@" . $self->ra->get_uuid;
1589
}
1590
+ $log_entry{name} = $name;
1591
+ $log_entry{email} = $email;
1592
\%log_entry;
1593
}
1594