@matheusbsbs / matheus-bagliano / commits / 98327e5891
Fork 0

git-svn: make multi-init less confusing

It now requires at least one of the (trunk|branch|tags) arguments (either from the command-line or in .git/config). Also we make sure that anything that is passed as a URL ('help') in David's case is actually a URL. Thanks to David Kågedal for reporting this issue. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed Jan 4, 2007 at 18:02 UTC 98327e5891471e7baceda5c6543a387f0dd21d3a
1 file changed +40 -38
git-svn.perl
+40 -38
@@ -571,28 +571,25 @@ sub graft_branches {
571
572 sub multi_init {
573 my $url = shift;
574 - $_trunk ||= 'trunk';
575 - $_trunk =~ s#/+$##;
576 - $url =~ s#/+$## if $url;
577 - if ($_trunk !~ m#^[a-z\+]+://#) {
578 - $_trunk = '/' . $_trunk if ($_trunk !~ m#^/#);
579 - unless ($url) {
580 - print STDERR "E: '$_trunk' is not a complete URL ",
581 - "and a separate URL is not specified\n";
582 - exit 1;
583 - }
584 - $_trunk = $url . $_trunk;
585 - }
586 - my $ch_id;
587 - if ($GIT_SVN eq 'git-svn') {
588 - $ch_id = 1;
589 - $GIT_SVN = $ENV{GIT_SVN_ID} = 'trunk';
574 + unless (defined $_trunk || defined $_branches || defined $_tags) {
575 + usage(1);
576 }
591 - init_vars();
592 - unless (-d $GIT_SVN_DIR) {
593 - print "GIT_SVN_ID set to 'trunk' for $_trunk\n" if $ch_id;
594 - init($_trunk);
595 - command_noisy('repo-config', 'svn.trunk', $_trunk);
577 + if (defined $_trunk) {
578 + my $trunk_url = complete_svn_url($url, $_trunk);
579 + my $ch_id;
580 + if ($GIT_SVN eq 'git-svn') {
581 + $ch_id = 1;
582 + $GIT_SVN = $ENV{GIT_SVN_ID} = 'trunk';
583 + }
584 + init_vars();
585 + unless (-d $GIT_SVN_DIR) {
586 + if ($ch_id) {
587 + print "GIT_SVN_ID set to 'trunk' for ",
588 + "$trunk_url ($_trunk)\n";
589 + }
590 + init($trunk_url);
591 + command_noisy('repo-config', 'svn.trunk', $trunk_url);
592 + }
593 }
594 complete_url_ls_init($url, $_branches, '--branches/-b', '');
595 complete_url_ls_init($url, $_tags, '--tags/-t', 'tags/');
@@ -872,29 +869,34 @@ sub rec_fetch {
869 }
870 }
871
872 +sub complete_svn_url {
873 + my ($url, $path) = @_;
874 + $path =~ s#/+$##;
875 + $url =~ s#/+$## if $url;
876 + if ($path !~ m#^[a-z\+]+://#) {
877 + $path = '/' . $path if ($path !~ m#^/#);
878 + if (!defined $url || $url !~ m#^[a-z\+]+://#) {
879 + fatal("E: '$path' is not a complete URL ",
880 + "and a separate URL is not specified\n");
881 + }
882 + $path = $url . $path;
883 + }
884 + return $path;
885 +}
886 +
887 sub complete_url_ls_init {
876 - my ($url, $var, $switch, $pfx) = @_;
877 - unless ($var) {
888 + my ($url, $path, $switch, $pfx) = @_;
889 + unless ($path) {
890 print STDERR "W: $switch not specified\n";
891 return;
892 }
881 - $var =~ s#/+$##;
882 - if ($var !~ m#^[a-z\+]+://#) {
883 - $var = '/' . $var if ($var !~ m#^/#);
884 - unless ($url) {
885 - print STDERR "E: '$var' is not a complete URL ",
886 - "and a separate URL is not specified\n";
887 - exit 1;
888 - }
889 - $var = $url . $var;
890 - }
891 - my @ls = libsvn_ls_fullurl($var);
892 - my $old = $GIT_SVN;
893 + my $full_url = complete_svn_url($url, $path);
894 + my @ls = libsvn_ls_fullurl($full_url);
895 defined(my $pid = fork) or croak $!;
896 if (!$pid) {
895 - foreach my $u (map { "$var/$_" } (grep m!/$!, @ls)) {
897 + foreach my $u (map { "$full_url/$_" } (grep m!/$!, @ls)) {
898 $u =~ s#/+$##;
897 - if ($u !~ m!\Q$var\E/(.+)$!) {
899 + if ($u !~ m!\Q$full_url\E/(.+)$!) {
900 print STDERR "W: Unrecognized URL: $u\n";
901 die "This should never happen\n";
902 }
@@ -912,7 +914,7 @@ sub complete_url_ls_init {
914 waitpid $pid, 0;
915 croak $? if $?;
916 my ($n) = ($switch =~ /^--(\w+)/);
915 - command_noisy('repo-config', "svn.$n", $var);
917 + command_noisy('repo-config', "svn.$n", $full_url);
918 }
919
920 sub common_prefix {