]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-cvsexportcommit.perl
Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR
[thirdparty/git.git] / git-cvsexportcommit.perl
index 92e41620fd2a998e765a47c2c2ca7085834b14cc..2a8ad1e9f4cbc2c21b83fd72fae1e0d2e582fbdc 100755 (executable)
@@ -5,6 +5,7 @@ use Getopt::Std;
 use File::Temp qw(tempdir);
 use Data::Dumper;
 use File::Basename qw(basename dirname);
+use File::Spec;
 
 our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w);
 
@@ -15,17 +16,15 @@ $opt_h && usage();
 die "Need at least one commit identifier!" unless @ARGV;
 
 if ($opt_w) {
+       # Remember where GIT_DIR is before changing to CVS checkout
        unless ($ENV{GIT_DIR}) {
-               # Remember where our GIT_DIR is before changing to CVS checkout
+               # No GIT_DIR set. Figure it out for ourselves
                my $gd =`git-rev-parse --git-dir`;
                chomp($gd);
-               if ($gd eq '.git') {
-                       my $wd = `pwd`;
-                       chomp($wd);
-                       $gd = $wd."/.git"       ;
-               }
                $ENV{GIT_DIR} = $gd;
        }
+       # Make sure GIT_DIR is absolute
+       $ENV{GIT_DIR} = File::Spec->rel2abs($ENV{GIT_DIR});
 
        if (! -d $opt_w."/CVS" ) {
                die "$opt_w is not a CVS checkout";
@@ -195,11 +194,11 @@ foreach my $f (@files) {
 my %cvsstat;
 if (@canstatusfiles) {
     if ($opt_u) {
-      my @updated = safe_pipe_capture(@cvs, 'update', @canstatusfiles);
+      my @updated = xargs_safe_pipe_capture([@cvs, 'update'], @canstatusfiles);
       print @updated;
     }
     my @cvsoutput;
-    @cvsoutput= safe_pipe_capture(@cvs, 'status', @canstatusfiles);
+    @cvsoutput = xargs_safe_pipe_capture([@cvs, 'status'], @canstatusfiles);
     my $matchcount = 0;
     foreach my $l (@cvsoutput) {
         chomp $l;
@@ -295,7 +294,7 @@ if ($dirtypatch) {
 
 if ($opt_c) {
     print "Autocommit\n  $cmd\n";
-    print safe_pipe_capture(@cvs, 'commit', '-F', '.msg', @files);
+    print xargs_safe_pipe_capture([@cvs, 'commit', '-F', '.msg'], @files);
     if ($?) {
        die "Exiting: The commit did not succeed";
     }
@@ -335,15 +334,24 @@ sub safe_pipe_capture {
     return wantarray ? @output : join('',@output);
 }
 
-sub safe_pipe_capture_blob {
-    my $output;
-    if (my $pid = open my $child, '-|') {
-        local $/;
-       undef $/;
-       $output = (<$child>);
-       close $child or die join(' ',@_).": $! $?";
-    } else {
-       exec(@_) or die "$! $?"; # exec() can fail the executable can't be found
-    }
-    return $output;
+sub xargs_safe_pipe_capture {
+       my $MAX_ARG_LENGTH = 65536;
+       my $cmd = shift;
+       my @output;
+       my $output;
+       while(@_) {
+               my @args;
+               my $length = 0;
+               while(@_ && $length < $MAX_ARG_LENGTH) {
+                       push @args, shift;
+                       $length += length($args[$#args]);
+               }
+               if (wantarray) {
+                       push @output, safe_pipe_capture(@$cmd, @args);
+               }
+               else {
+                       $output .= safe_pipe_capture(@$cmd, @args);
+               }
+       }
+       return wantarray ? @output : $output;
 }