cvsimport: ignore CVSPS_NO_BRANCH and impossible branches
[git.git] / git-cvsimport.perl
index 41ee9a6..d83c52f 100755 (executable)
@@ -23,7 +23,7 @@ use File::Basename qw(basename dirname);
 use Time::Local;
 use IO::Socket;
 use IO::Pipe;
-use POSIX qw(strftime dup2 :errno_h);
+use POSIX qw(strftime dup2 ENOENT);
 use IPC::Open2;
 
 $SIG{'PIPE'}="IGNORE";
@@ -371,7 +371,7 @@ sub file {
 }
 sub _fetchfile {
        my ($self, $fh, $cnt) = @_;
-       my $res;
+       my $res = 0;
        my $bufsize = 1024 * 1024;
        while($cnt) {
            if ($bufsize > $cnt) {
@@ -595,7 +595,11 @@ sub write_tree () {
 }
 
 my($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
-my(@old,@new,@skipped);
+my(@old,@new,@skipped,%ignorebranch);
+
+# commits that cvsps cannot place anywhere...
+$ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
+
 sub commit {
        update_index(@old, @new);
        @old = @new = ();
@@ -618,14 +622,13 @@ sub commit {
        }
 
        my $commit_date = strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date));
+       $ENV{GIT_AUTHOR_NAME} = $author_name;
+       $ENV{GIT_AUTHOR_EMAIL} = $author_email;
+       $ENV{GIT_AUTHOR_DATE} = $commit_date;
+       $ENV{GIT_COMMITTER_NAME} = $author_name;
+       $ENV{GIT_COMMITTER_EMAIL} = $author_email;
+       $ENV{GIT_COMMITTER_DATE} = $commit_date;
        my $pid = open2(my $commit_read, my $commit_write,
-               'env',
-               "GIT_AUTHOR_NAME=$author_name",
-               "GIT_AUTHOR_EMAIL=$author_email",
-               "GIT_AUTHOR_DATE=$commit_date",
-               "GIT_COMMITTER_NAME=$author_name",
-               "GIT_COMMITTER_EMAIL=$author_email",
-               "GIT_COMMITTER_DATE=$commit_date",
                'git-commit-tree', $tree, @commit_args);
 
        # compatibility with git2cvs
@@ -752,7 +755,16 @@ while(<CVS>) {
                        $state = 11;
                        next;
                }
+               if (exists $ignorebranch{$branch}) {
+                       print STDERR "Skipping $branch\n";
+                       $state = 11;
+                       next;
+               }
                if($ancestor) {
+                       if($ancestor eq $branch) {
+                               print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
+                               $ancestor = $opt_o;
+                       }
                        if(-f "$git_dir/refs/heads/$branch") {
                                print STDERR "Branch $branch already exists!\n";
                                $state=11;
@@ -760,6 +772,7 @@ while(<CVS>) {
                        }
                        unless(open(H,"$git_dir/refs/heads/$ancestor")) {
                                print STDERR "Branch $ancestor does not exist!\n";
+                               $ignorebranch{$branch} = 1;
                                $state=11;
                                next;
                        }
@@ -767,6 +780,7 @@ while(<CVS>) {
                        close(H);
                        unless(open(H,"> $git_dir/refs/heads/$branch")) {
                                print STDERR "Could not create branch $branch: $!\n";
+                               $ignorebranch{$branch} = 1;
                                $state=11;
                                next;
                        }