git-cvsimport-script: more error handling
[git.git] / git-cvsimport-script
index 62df916..7f93fb3 100755 (executable)
@@ -28,19 +28,19 @@ use POSIX qw(strftime dup2);
 $SIG{'PIPE'}="IGNORE";
 $ENV{'TZ'}="UTC";
 
-our($opt_h,$opt_o,$opt_v,$opt_d,$opt_p,$opt_C);
+our($opt_h,$opt_o,$opt_v,$opt_d,$opt_p,$opt_C,$opt_z);
 
 sub usage() {
        print STDERR <<END;
 Usage: ${\basename $0}     # fetch/update GIT from CVS
-          [ -o branch-for-HEAD ] [ -h ] [ -v ] [ -d CVSROOT ]
-       [ -p opts-for-cvsps ] [ -C GIT_repository ]
+       [ -o branch-for-HEAD ] [ -h ] [ -v ] [ -d CVSROOT ]
+       [ -p opts-for-cvsps ] [ -C GIT_repository ] [ -z fuzz ]
        [ CVS_module ]
 END
        exit(1);
 }
 
-getopts("hqvo:d:p:C:") or usage();
+getopts("hqvo:d:p:C:z:") or usage();
 usage if $opt_h;
 
 @ARGV <= 1 or usage();
@@ -408,6 +408,7 @@ unless(-d $git_dir) {
 
        # populate index
        system('git-read-tree', $last_branch);
+       die "read-tree failed: $?\n" if $?;
 
        # Get the last import timestamps
        opendir(D,"$git_dir/refs/heads");
@@ -436,6 +437,7 @@ die "Cannot fork: $!\n" unless defined $pid;
 unless($pid) {
        my @opt;
        @opt = split(/,/,$opt_p) if defined $opt_p;
+       unshift @opt, '-z', $opt_z if defined $opt_z;
        exec("cvsps",@opt,"-u","-A","--cvs-direct",'--root',$opt_d,$cvs_tree);
        die "Could not start cvsps: $!\n";
 }
@@ -509,8 +511,8 @@ my $commit = sub {
                print "Parent ID $parent\n" if $opt_v;
        }
 
-       my $pr = IO::Pipe->new();
-       my $pw = IO::Pipe->new();
+       my $pr = IO::Pipe->new() or die "Cannot open pipe: $!\n";
+       my $pw = IO::Pipe->new() or die "Cannot open pipe: $!\n";
        $pid = fork();
        die "Fork: $!\n" unless defined $pid;
        unless($pid) {