]> asedeno.scripts.mit.edu Git - git.git/blobdiff - git-cvsimport.perl
gitweb: Add links to blobdiffs in from-file/to-file header for merges
[git.git] / git-cvsimport.perl
index 1a1ba7b1a6f779773702ae3c1efb56425c31beb4..3225a2a25dcaabbae64754e99a550f5b210f3765 100755 (executable)
@@ -32,12 +32,15 @@ $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_P, $opt_s,$opt_m,$opt_M,$opt_A,$opt_S,$opt_L, $opt_a);
 my (%conv_author_name, %conv_author_email);
 
-sub usage() {
+sub usage(;$) {
+       my $msg = shift;
+       print(STDERR "Error: $msg\n") if $msg;
        print STDERR <<END;
 Usage: ${\basename $0}     # fetch/update GIT from CVS
        [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
-       [-p opts-for-cvsps] [-C GIT_repository] [-z fuzz] [-i] [-k] [-u]
-       [-s subst] [-a] [-m] [-M regex] [-S regex] [CVS_module]
+       [-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
+       [-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
+       [CVS_module]
 END
        exit(1);
 }
@@ -116,7 +119,7 @@ read_repo_config($opts);
 getopts($opts) or usage();
 usage if $opt_h;
 
-@ARGV <= 1 or usage();
+@ARGV <= 1 or usage("You can't specify more than one CVS module");
 
 if ($opt_d) {
        $ENV{"CVSROOT"} = $opt_d;
@@ -129,7 +132,7 @@ if ($opt_d) {
 } elsif ($ENV{"CVSROOT"}) {
        $opt_d = $ENV{"CVSROOT"};
 } else {
-       die "CVSROOT needs to be set";
+       usage("CVSROOT needs to be set");
 }
 $opt_o ||= "origin";
 $opt_s ||= "-";
@@ -142,13 +145,13 @@ my $cvs_tree;
 if ($#ARGV == 0) {
        $cvs_tree = $ARGV[0];
 } elsif (-f 'CVS/Repository') {
-       open my $f, '<', 'CVS/Repository' or 
+       open my $f, '<', 'CVS/Repository' or
            die 'Failed to open CVS/Repository';
        $cvs_tree = <$f>;
        chomp $cvs_tree;
        close $f;
 } else {
-       usage();
+       usage("CVS module has to be specified");
 }
 
 our @mergerx = ();
@@ -431,7 +434,7 @@ sub file {
        my ($self,$fn,$rev) = @_;
        my $res;
 
-       my ($fh, $name) = tempfile('gitcvs.XXXXXX', 
+       my ($fh, $name) = tempfile('gitcvs.XXXXXX',
                    DIR => File::Spec->tmpdir(), UNLINK => 1);
 
        $self->_file($fn,$rev) and $res = $self->_line($fh);
@@ -517,8 +520,8 @@ sub is_sha1 {
 
 sub get_headref ($$) {
     my $name    = shift;
-    my $git_dir = shift; 
-    
+    my $git_dir = shift;
+
     my $f = "$git_dir/refs/heads/$name";
     if (open(my $fh, $f)) {
            chomp(my $r = <$fh>);
@@ -556,11 +559,6 @@ unless (-d $git_dir) {
        $last_branch = $opt_o;
        $orig_branch = "";
 } else {
-       -f "$git_dir/refs/heads/$opt_o"
-               or die "Branch '$opt_o' does not exist.\n".
-                      "Either use the correct '-o branch' option,\n".
-                      "or import to a new repository.\n";
-
        open(F, "git-symbolic-ref HEAD |") or
                die "Cannot run git-symbolic-ref: $!\n";
        chomp ($last_branch = <F>);
@@ -585,6 +583,11 @@ unless (-d $git_dir) {
                $branch_date{$head} = $1;
        }
        close(H);
+        if (!exists $branch_date{$opt_o}) {
+               die "Branch '$opt_o' does not exist.\n".
+                      "Either use the correct '-o branch' option,\n".
+                      "or import to a new repository.\n";
+        }
 }
 
 -d $git_dir
@@ -689,8 +692,8 @@ sub commit {
        if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) {
            # looks like an initial commit
            # use the index primed by git-init
-           $ENV{GIT_INDEX_FILE} = '.git/index';
-           $index{$branch} = '.git/index';
+           $ENV{GIT_INDEX_FILE} = "$git_dir/index";
+           $index{$branch} = "$git_dir/index";
        } else {
            # use an index per branch to speed up
            # imports of projects with many branches
@@ -768,7 +771,7 @@ sub commit {
                $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".
                    "type commit\n".
@@ -785,7 +788,7 @@ sub commit {
                     $? != 0 or $tagobj !~ /^[0123456789abcdef]{40}$/ ) {
                    die "Cannot create tag object $xtag: $!\n";
                }
-               
+
 
                open(C,">$git_dir/refs/tags/$xtag")
                        or die "Cannot create tag $xtag: $!\n";
@@ -981,7 +984,7 @@ if ($line =~ /^(\d+) objects, (\d+) kilobytes$/) {
 }
 
 foreach my $git_index (values %index) {
-    if ($git_index ne '.git/index') {
+    if ($git_index ne "$git_dir/index") {
        unlink($git_index);
     }
 }