git-svn: make multi-init capable of reusing the Ra connection
If a user specified a seperate URL and --tags/--branches as a sepearte URL, allow the Ra object (and therefore the connection) to be reused. We'll get rid of libsvn_ls_fullurl() since it was only used in one place. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jan 11, 2007 at 17:09 UTC
e7db67e6f18495332c4d688d3291b05851526a6e
2 files changed
+29
-27
git-svn.perl
+23
-27
@@ -595,8 +595,9 @@ sub cmd_multi_init {
595
command_noisy('config', 'svn.trunk', $trunk_url);
596
}
597
}
598
- complete_url_ls_init($url, $_branches, '--branches/-b', $_prefix);
599
- complete_url_ls_init($url, $_tags, '--tags/-t', $_prefix . 'tags/');
598
+ my $ra = $url ? Git::SVN::Ra->new($url) : undef;
599
+ complete_url_ls_init($ra, $_branches, '--branches/-b', $_prefix);
600
+ complete_url_ls_init($ra, $_tags, '--tags/-t', $_prefix . 'tags/');
601
}
602
603
sub multi_fetch {
@@ -890,29 +891,38 @@ sub complete_svn_url {
891
}
892
893
sub complete_url_ls_init {
893
- my ($url, $path, $switch, $pfx) = @_;
894
+ my ($ra, $path, $switch, $pfx) = @_;
895
unless ($path) {
896
print STDERR "W: $switch not specified\n";
897
return;
898
}
898
- my $full_url = complete_svn_url($url, $path);
899
- my @ls = libsvn_ls_fullurl($full_url);
900
- foreach my $u (map { "$full_url/$_" } (grep m!/$!, @ls)) {
901
- $u =~ s#/+$##;
902
- if ($u !~ m!\Q$full_url\E/(.+)$!) {
903
- print STDERR "W: Unrecognized URL: $u\n";
904
- die "This should never happen\n";
899
+ $path =~ s#/+$##;
900
+ if ($path =~ m#^[a-z\+]+://#) {
901
+ $ra = Git::SVN::Ra->new($path);
902
+ $path = '';
903
+ } else {
904
+ $path =~ s#^/+##;
905
+ unless ($ra) {
906
+ fatal("E: '$path' is not a complete URL ",
907
+ "and a separate URL is not specified\n");
908
}
906
- # don't try to init already existing refs
907
- my $id = $pfx.$1;
909
+ }
910
+ my $r = defined $_revision ? $_revision : $ra->get_latest_revnum;
911
+ my ($dirent, undef, undef) = $ra->get_dir($path, $r);
912
+ my $url = $ra->{url} . (length $path ? "/$path" : '');
913
+ foreach my $d (sort keys %$dirent) {
914
+ next if ($dirent->{$d}->kind != $SVN::Node::dir);
915
+ my $u = "$url/$d";
916
+ my $id = "$pfx$d";
917
my $gs = eval { Git::SVN->new($id) };
918
+ # don't try to init already existing refs
919
unless ($gs) {
920
print "init $u => $id\n";
921
Git::SVN->init($id, $u);
922
}
923
}
924
my ($n) = ($switch =~ /^--(\w+)/);
915
- command_noisy('config', "svn.$n", $full_url);
925
+ command_noisy('config', "svn.$n", $url);
926
}
927
928
sub common_prefix {
@@ -2851,20 +2861,6 @@ sub libsvn_commit_cb {
2861
}
2862
}
2863
2854
-sub libsvn_ls_fullurl {
2855
- my $fullurl = shift;
2856
- my $ra = Git::SVN::Ra->new($fullurl);
2857
- my @ret;
2858
- my $r = defined $_revision ? $_revision : $ra->get_latest_revnum;
2859
- my ($dirent, undef, undef) = $ra->get_dir('', $r);
2860
- foreach my $d (sort keys %$dirent) {
2861
- if ($dirent->{$d}->kind == $SVN::Node::dir) {
2862
- push @ret, "$d/"; # add '/' for compat with cli svn
2863
- }
2864
- }
2865
- return @ret;
2866
-}
2867
-
2864
sub libsvn_skip_unknown_revs {
2865
my $err = shift;
2866
my $errno = $err->apr_err();
t/t9103-git-svn-graft-branches.sh
+6
@@ -26,6 +26,12 @@ test_expect_success 'initialize repo' "
26
git-svn multi-fetch
27
"
28
29
+test_expect_success 'multi-init set .git/config correctly' "
30
+ test '$svnrepo/trunk' = '`git repo-config --get svn.trunk`' &&
31
+ test '$svnrepo/branches' = '`git repo-config --get svn.branches`' &&
32
+ test '$svnrepo/tags' = '`git repo-config --get svn.tags`'
33
+ "
34
+
35
r1=`git-rev-list remotes/trunk | tail -n1`
36
r2=`git-rev-list remotes/tags/a | tail -n1`
37
r3=`git-rev-list remotes/a | tail -n1`