@@ -356,7 +356,7 @@ sub req_Root
356356 return 0;
357357 }
358358
359- my @gitvars = ` git config -l` ;
359+ my @gitvars = safe_pipe_capture( qw( git config -l) ) ;
360360 if ($? ) {
361361 print " E problems executing git-config on the server -- this is not a git repository or the PATH is not set correctly.\n " ;
362362 print " E \n " ;
@@ -841,7 +841,7 @@ sub req_Modified
841841 # Save the file data in $state
842842 $state -> {entries }{$state -> {directory }.$data }{modified_filename } = $filename ;
843843 $state -> {entries }{$state -> {directory }.$data }{modified_mode } = $mode ;
844- $state -> {entries }{$state -> {directory }.$data }{modified_hash } = ` git hash-object $filename ` ;
844+ $state -> {entries }{$state -> {directory }.$data }{modified_hash } = safe_pipe_capture( ' git' , ' hash-object' , $filename ) ;
845845 $state -> {entries }{$state -> {directory }.$data }{modified_hash } =~ s /\s .*$// s ;
846846
847847 # $log->debug("req_Modified : file=$data mode=$mode size=$size");
@@ -943,7 +943,7 @@ sub req_co
943943
944944 # Provide list of modules, if -c was used.
945945 if (exists $state -> {opt }{c }) {
946- my $showref = ` git show-ref --heads` ;
946+ my $showref = safe_pipe_capture( qw( git show-ref --heads) ) ;
947947 for my $line (split ' \n' , $showref ) {
948948 if ( $line =~ m % refs/heads/(.*)$ % ) {
949949 print " M $1 \t $1 \n " ;
@@ -1181,7 +1181,7 @@ sub req_update
11811181 # projects (heads in this case) to checkout.
11821182 #
11831183 if ($state -> {module } eq ' ' ) {
1184- my $showref = ` git show-ref --heads` ;
1184+ my $showref = safe_pipe_capture( qw( git show-ref --heads) ) ;
11851185 print " E cvs update: Updating .\n " ;
11861186 for my $line (split ' \n' , $showref ) {
11871187 if ( $line =~ m % refs/heads/(.*)$ % ) {
@@ -1463,7 +1463,7 @@ sub req_update
14631463 # transmit file, format is single integer on a line by itself (file
14641464 # size) followed by the file contents
14651465 # TODO : we should copy files in blocks
1466- my $data = ` cat $mergedFile ` ;
1466+ my $data = safe_pipe_capture( ' cat' , $mergedFile ) ;
14671467 $log -> debug(" File size : " . length ($data ));
14681468 print length ($data ) . " \n " ;
14691469 print $data ;
@@ -1579,7 +1579,7 @@ sub req_ci
15791579 $branchRef = " refs/heads/$stickyInfo ->{tag}" ;
15801580 }
15811581
1582- $parenthash = ` git show-ref -s $branchRef ` ;
1582+ $parenthash = safe_pipe_capture( ' git' , ' show-ref' , ' -s ' , $branchRef ) ;
15831583 chomp $parenthash ;
15841584 if ($parenthash !~ / ^[0-9a-f]{40}$ / )
15851585 {
@@ -1687,7 +1687,7 @@ sub req_ci
16871687 return ;
16881688 }
16891689
1690- my $treehash = ` git write-tree` ;
1690+ my $treehash = safe_pipe_capture( qw( git write-tree) ) ;
16911691 chomp $treehash ;
16921692
16931693 $log -> debug(" Treehash : $treehash , Parenthash : $parenthash " );
@@ -1704,7 +1704,7 @@ sub req_ci
17041704 }
17051705 close $msg_fh ;
17061706
1707- my $commithash = ` git commit-tree $treehash -p $parenthash < $msg_filename ` ;
1707+ my $commithash = safe_pipe_capture( ' git' , ' commit-tree' , $treehash , ' -p ' , $parenthash , ' -F ' , $msg_filename ) ;
17081708 chomp ($commithash );
17091709 $log -> info(" Commit hash : $commithash " );
17101710
@@ -2854,12 +2854,12 @@ sub transmitfile
28542854
28552855 die " Need filehash" unless ( defined ( $filehash ) and $filehash =~ / ^[a-zA-Z0-9]{40}$ / );
28562856
2857- my $type = ` git cat-file -t $filehash ` ;
2857+ my $type = safe_pipe_capture( ' git' , ' cat-file' , ' -t ' , $filehash ) ;
28582858 chomp $type ;
28592859
28602860 die ( " Invalid type '$type ' (expected 'blob')" ) unless ( defined ( $type ) and $type eq " blob" );
28612861
2862- my $size = ` git cat-file -s $filehash ` ;
2862+ my $size = safe_pipe_capture( ' git' , ' cat-file' , ' -s ' , $filehash ) ;
28632863 chomp $size ;
28642864
28652865 $log -> debug(" transmitfile($filehash ) size=$size , type=$type " );
@@ -3040,7 +3040,7 @@ sub ensureWorkTree
30403040 chdir $work -> {emptyDir } or
30413041 die " Unable to chdir to $work ->{emptyDir}\n " ;
30423042
3043- my $ver = ` git show-ref -s refs/heads/$state ->{module}` ;
3043+ my $ver = safe_pipe_capture( ' git' , ' show-ref' , ' -s ' , " refs/heads/$state ->{module}" ) ;
30443044 chomp $ver ;
30453045 if ($ver !~ / ^[0-9a-f]{40}$ / )
30463046 {
@@ -3287,7 +3287,7 @@ sub open_blob_or_die
32873287 die " Need filehash\n " ;
32883288 }
32893289
3290- my $type = ` git cat-file -t $name ` ;
3290+ my $type = safe_pipe_capture( ' git' , ' cat-file' , ' -t ' , $name ) ;
32913291 chomp $type ;
32923292
32933293 unless ( defined ( $type ) and $type eq " blob" )
@@ -3296,7 +3296,7 @@ sub open_blob_or_die
32963296 die ( " Invalid type '$type ' (expected 'blob')" )
32973297 }
32983298
3299- my $size = ` git cat-file -s $name ` ;
3299+ my $size = safe_pipe_capture( ' git' , ' cat-file' , ' -s ' , $name ) ;
33003300 chomp $size ;
33013301
33023302 $log -> debug(" open_blob_or_die($name ) size=$size , type=$type " );
@@ -3406,6 +3406,22 @@ sub refHashEqual
34063406 return $out ;
34073407}
34083408
3409+ # an alternative to `command` that allows input to be passed as an array
3410+ # to work around shell problems with weird characters in arguments
3411+
3412+ sub safe_pipe_capture {
3413+
3414+ my @output ;
3415+
3416+ if (my $pid = open my $child , ' -|' ) {
3417+ @output = (<$child >);
3418+ close $child or die join (' ' ,@_ )." : $! $? " ;
3419+ } else {
3420+ exec (@_ ) or die " $! $? " ; # exec() can fail the executable can't be found
3421+ }
3422+ return wantarray ? @output : join (' ' ,@output );
3423+ }
3424+
34093425
34103426package GITCVS::log ;
34113427
@@ -3797,10 +3813,10 @@ sub update
37973813 # first lets get the commit list
37983814 $ENV {GIT_DIR } = $self -> {git_path };
37993815
3800- my $commitsha1 = ` git rev-parse $self ->{module}` ;
3816+ my $commitsha1 = ::safe_pipe_capture( ' git' , ' rev-parse' , $self -> {module }) ;
38013817 chomp $commitsha1 ;
38023818
3803- my $commitinfo = ` git cat-file commit $self ->{module} 2>&1 ` ;
3819+ my $commitinfo = ::safe_pipe_capture( ' git' , ' cat-file' , ' commit' , $self -> {module }) ;
38043820 unless ( $commitinfo =~ / tree\s +[a-zA-Z0-9]{40}/ )
38053821 {
38063822 die (" Invalid module '$self ->{module}'" );
@@ -3882,7 +3898,7 @@ sub update
38823898 # several candidate merge bases. let's assume
38833899 # that the first one is the best one.
38843900 my $base = eval {
3885- safe_pipe_capture(' git' , ' merge-base' ,
3901+ :: safe_pipe_capture(' git' , ' merge-base' ,
38863902 $lastpicked , $parent );
38873903 };
38883904 # The two branches may not be related at all,
@@ -4749,7 +4765,7 @@ sub getMetaFromCommithash
47494765 return $retVal ;
47504766 }
47514767
4752- my ($fileHash )= safe_pipe_capture(" git" ," rev-parse" ," $revCommit :$filename " );
4768+ my ($fileHash ) = :: safe_pipe_capture(" git" ," rev-parse" ," $revCommit :$filename " );
47534769 chomp $fileHash ;
47544770 if (!($fileHash =~/ ^[0-9a-f]{40}$ / ))
47554771 {
@@ -4844,8 +4860,8 @@ sub lookupCommitRef
48444860 return $commitHash ;
48454861 }
48464862
4847- $commitHash = safe_pipe_capture(" git" ," rev-parse" ," --verify" ," --quiet" ,
4848- $self -> unescapeRefName($ref ));
4863+ $commitHash = :: safe_pipe_capture(" git" ," rev-parse" ," --verify" ," --quiet" ,
4864+ $self -> unescapeRefName($ref ));
48494865 $commitHash =~s /\s *$// ;
48504866 if (!($commitHash =~/ ^[0-9a-f]{40}$ / ))
48514867 {
@@ -4854,7 +4870,7 @@ sub lookupCommitRef
48544870
48554871 if ( defined ($commitHash ) )
48564872 {
4857- my $type = safe_pipe_capture(" git" ," cat-file" ," -t" ,$commitHash );
4873+ my $type = :: safe_pipe_capture(" git" ," cat-file" ," -t" ,$commitHash );
48584874 if ( ! ($type =~/ ^commit\s *$ / ) )
48594875 {
48604876 $commitHash =undef ;
@@ -4907,7 +4923,7 @@ sub commitmessage
49074923 return $message ;
49084924 }
49094925
4910- my @lines = safe_pipe_capture(" git" , " cat-file" , " commit" , $commithash );
4926+ my @lines = :: safe_pipe_capture(" git" , " cat-file" , " commit" , $commithash );
49114927 shift @lines while ( $lines [0] =~ / \S / );
49124928 $message = join (" " ,@lines );
49134929 $message .= " " if ( $message =~ / \n $ / );
@@ -5056,25 +5072,6 @@ sub in_array
50565072 return $retval ;
50575073}
50585074
5059- =head2 safe_pipe_capture
5060-
5061- an alternative to `command` that allows input to be passed as an array
5062- to work around shell problems with weird characters in arguments
5063-
5064- =cut
5065- sub safe_pipe_capture {
5066-
5067- my @output ;
5068-
5069- if (my $pid = open my $child , ' -|' ) {
5070- @output = (<$child >);
5071- close $child or die join (' ' ,@_ )." : $! $? " ;
5072- } else {
5073- exec (@_ ) or die " $! $? " ; # exec() can fail the executable can't be found
5074- }
5075- return wantarray ? @output : join (' ' ,@output );
5076- }
5077-
50785075=head2 mangle_dirname
50795076
50805077create a string from a directory name that is suitable to use as
0 commit comments