git-fetch-pack: really do not ask for funny refs
[git.git] / git-cvsimport.perl
index 0621dc3..8619e7d 100755 (executable)
@@ -29,7 +29,7 @@ use IPC::Open2;
 $SIG{'PIPE'}="IGNORE";
 $ENV{'TZ'}="UTC";
 
-our($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_s,$opt_m,$opt_M);
+our($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,$opt_M);
 
 sub usage() {
        print STDERR <<END;
@@ -41,7 +41,7 @@ END
        exit(1);
 }
 
-getopts("hivmkuo:d:p:C:z:s:M:") or usage();
+getopts("hivmkuo:d:p:C:z:s:M:P:") or usage();
 usage if $opt_h;
 
 @ARGV <= 1 or usage();
@@ -337,6 +337,10 @@ sub file {
        }
        close ($fh);
 
+       if ($res eq '') {
+           die "Looks like the server has gone away while fetching $fn $rev -- exiting!";
+       }
+
        return ($name, $res);
 }
 
@@ -433,7 +437,11 @@ unless(-d $git_dir) {
                       "Either use the correct '-o branch' option,\n".
                       "or import to a new repository.\n";
 
-       $last_branch = basename(readlink("$git_dir/HEAD"));
+       open(F, "git-symbolic-ref HEAD |") or
+               die "Cannot run git-symbolic-ref: $!\n";
+       chomp ($last_branch = <F>);
+       $last_branch = basename($last_branch);
+       close(F);
        unless($last_branch) {
                warn "Cannot read the last branch name: $! -- assuming 'master'\n";
                $last_branch = "master";
@@ -487,11 +495,16 @@ unless($pid) {
        my @opt;
        @opt = split(/,/,$opt_p) if defined $opt_p;
        unshift @opt, '-z', $opt_z if defined $opt_z;
-       unless ($opt_p =~ m/--no-cvs-direct/) {
+       unshift @opt, '-q'         unless defined $opt_v;
+       unless (defined($opt_p) && $opt_p =~ m/--no-cvs-direct/) {
                push @opt, '--cvs-direct';
        }
-       exec("cvsps",@opt,"-u","-A",'--root',$opt_d,$cvs_tree);
-       die "Could not start cvsps: $!\n";
+       if ($opt_P) {
+           exec("cat", $opt_P);
+       } else {
+           exec("cvsps","--norc",@opt,"-u","-A",'--root',$opt_d,$cvs_tree);
+           die "Could not start cvsps: $!\n";
+       }
 }
 
 
@@ -636,6 +649,7 @@ my $commit = sub {
                my($xtag) = $tag;
                $xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
                $xtag =~ tr/_/\./ if ( $opt_u );
+               $xtag =~ s/[\/]/$opt_s/g;
                
                my $pid = open2($in, $out, 'git-mktag');
                print $out "object $cid\n".
@@ -820,8 +834,7 @@ if($orig_branch) {
        print "DONE; creating $orig_branch branch\n" if $opt_v;
        system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
                unless -f "$git_dir/refs/heads/master";
-       unlink("$git_dir/HEAD");
-       symlink("refs/heads/$orig_branch","$git_dir/HEAD");
+       system('git-update-ref', 'HEAD', "$orig_branch");
        unless ($opt_i) {
                system('git checkout');
                die "checkout failed: $?\n" if $?;