@@ -356,7 +356,7 @@ sub req_Root
356
356
return 0;
357
357
}
358
358
359
- my @gitvars = ` git config -l` ;
359
+ my @gitvars = safe_pipe_capture( qw( git config -l) ) ;
360
360
if ($? ) {
361
361
print " E problems executing git-config on the server -- this is not a git repository or the PATH is not set correctly.\n " ;
362
362
print " E \n " ;
@@ -841,7 +841,7 @@ sub req_Modified
841
841
# Save the file data in $state
842
842
$state -> {entries }{$state -> {directory }.$data }{modified_filename } = $filename ;
843
843
$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 ) ;
845
845
$state -> {entries }{$state -> {directory }.$data }{modified_hash } =~ s /\s .*$// s ;
846
846
847
847
# $log->debug("req_Modified : file=$data mode=$mode size=$size");
@@ -943,7 +943,7 @@ sub req_co
943
943
944
944
# Provide list of modules, if -c was used.
945
945
if (exists $state -> {opt }{c }) {
946
- my $showref = ` git show-ref --heads` ;
946
+ my $showref = safe_pipe_capture( qw( git show-ref --heads) ) ;
947
947
for my $line (split ' \n' , $showref ) {
948
948
if ( $line =~ m % refs/heads/(.*)$ % ) {
949
949
print " M $1 \t $1 \n " ;
@@ -1181,7 +1181,7 @@ sub req_update
1181
1181
# projects (heads in this case) to checkout.
1182
1182
#
1183
1183
if ($state -> {module } eq ' ' ) {
1184
- my $showref = ` git show-ref --heads` ;
1184
+ my $showref = safe_pipe_capture( qw( git show-ref --heads) ) ;
1185
1185
print " E cvs update: Updating .\n " ;
1186
1186
for my $line (split ' \n' , $showref ) {
1187
1187
if ( $line =~ m % refs/heads/(.*)$ % ) {
@@ -1463,7 +1463,7 @@ sub req_update
1463
1463
# transmit file, format is single integer on a line by itself (file
1464
1464
# size) followed by the file contents
1465
1465
# TODO : we should copy files in blocks
1466
- my $data = ` cat $mergedFile ` ;
1466
+ my $data = safe_pipe_capture( ' cat' , $mergedFile ) ;
1467
1467
$log -> debug(" File size : " . length ($data ));
1468
1468
print length ($data ) . " \n " ;
1469
1469
print $data ;
@@ -1579,7 +1579,7 @@ sub req_ci
1579
1579
$branchRef = " refs/heads/$stickyInfo ->{tag}" ;
1580
1580
}
1581
1581
1582
- $parenthash = ` git show-ref -s $branchRef ` ;
1582
+ $parenthash = safe_pipe_capture( ' git' , ' show-ref' , ' -s ' , $branchRef ) ;
1583
1583
chomp $parenthash ;
1584
1584
if ($parenthash !~ / ^[0-9a-f]{40}$ / )
1585
1585
{
@@ -1687,7 +1687,7 @@ sub req_ci
1687
1687
return ;
1688
1688
}
1689
1689
1690
- my $treehash = ` git write-tree` ;
1690
+ my $treehash = safe_pipe_capture( qw( git write-tree) ) ;
1691
1691
chomp $treehash ;
1692
1692
1693
1693
$log -> debug(" Treehash : $treehash , Parenthash : $parenthash " );
@@ -1704,7 +1704,7 @@ sub req_ci
1704
1704
}
1705
1705
close $msg_fh ;
1706
1706
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 ) ;
1708
1708
chomp ($commithash );
1709
1709
$log -> info(" Commit hash : $commithash " );
1710
1710
@@ -2854,12 +2854,12 @@ sub transmitfile
2854
2854
2855
2855
die " Need filehash" unless ( defined ( $filehash ) and $filehash =~ / ^[a-zA-Z0-9]{40}$ / );
2856
2856
2857
- my $type = ` git cat-file -t $filehash ` ;
2857
+ my $type = safe_pipe_capture( ' git' , ' cat-file' , ' -t ' , $filehash ) ;
2858
2858
chomp $type ;
2859
2859
2860
2860
die ( " Invalid type '$type ' (expected 'blob')" ) unless ( defined ( $type ) and $type eq " blob" );
2861
2861
2862
- my $size = ` git cat-file -s $filehash ` ;
2862
+ my $size = safe_pipe_capture( ' git' , ' cat-file' , ' -s ' , $filehash ) ;
2863
2863
chomp $size ;
2864
2864
2865
2865
$log -> debug(" transmitfile($filehash ) size=$size , type=$type " );
@@ -3040,7 +3040,7 @@ sub ensureWorkTree
3040
3040
chdir $work -> {emptyDir } or
3041
3041
die " Unable to chdir to $work ->{emptyDir}\n " ;
3042
3042
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}" ) ;
3044
3044
chomp $ver ;
3045
3045
if ($ver !~ / ^[0-9a-f]{40}$ / )
3046
3046
{
@@ -3287,7 +3287,7 @@ sub open_blob_or_die
3287
3287
die " Need filehash\n " ;
3288
3288
}
3289
3289
3290
- my $type = ` git cat-file -t $name ` ;
3290
+ my $type = safe_pipe_capture( ' git' , ' cat-file' , ' -t ' , $name ) ;
3291
3291
chomp $type ;
3292
3292
3293
3293
unless ( defined ( $type ) and $type eq " blob" )
@@ -3296,7 +3296,7 @@ sub open_blob_or_die
3296
3296
die ( " Invalid type '$type ' (expected 'blob')" )
3297
3297
}
3298
3298
3299
- my $size = ` git cat-file -s $name ` ;
3299
+ my $size = safe_pipe_capture( ' git' , ' cat-file' , ' -s ' , $name ) ;
3300
3300
chomp $size ;
3301
3301
3302
3302
$log -> debug(" open_blob_or_die($name ) size=$size , type=$type " );
@@ -3406,6 +3406,22 @@ sub refHashEqual
3406
3406
return $out ;
3407
3407
}
3408
3408
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
+
3409
3425
3410
3426
package GITCVS::log ;
3411
3427
@@ -3797,10 +3813,10 @@ sub update
3797
3813
# first lets get the commit list
3798
3814
$ENV {GIT_DIR } = $self -> {git_path };
3799
3815
3800
- my $commitsha1 = ` git rev-parse $self ->{module}` ;
3816
+ my $commitsha1 = ::safe_pipe_capture( ' git' , ' rev-parse' , $self -> {module }) ;
3801
3817
chomp $commitsha1 ;
3802
3818
3803
- my $commitinfo = ` git cat-file commit $self ->{module} 2>&1 ` ;
3819
+ my $commitinfo = ::safe_pipe_capture( ' git' , ' cat-file' , ' commit' , $self -> {module }) ;
3804
3820
unless ( $commitinfo =~ / tree\s +[a-zA-Z0-9]{40}/ )
3805
3821
{
3806
3822
die (" Invalid module '$self ->{module}'" );
@@ -3882,7 +3898,7 @@ sub update
3882
3898
# several candidate merge bases. let's assume
3883
3899
# that the first one is the best one.
3884
3900
my $base = eval {
3885
- safe_pipe_capture(' git' , ' merge-base' ,
3901
+ :: safe_pipe_capture(' git' , ' merge-base' ,
3886
3902
$lastpicked , $parent );
3887
3903
};
3888
3904
# The two branches may not be related at all,
@@ -4749,7 +4765,7 @@ sub getMetaFromCommithash
4749
4765
return $retVal ;
4750
4766
}
4751
4767
4752
- my ($fileHash )= safe_pipe_capture(" git" ," rev-parse" ," $revCommit :$filename " );
4768
+ my ($fileHash ) = :: safe_pipe_capture(" git" ," rev-parse" ," $revCommit :$filename " );
4753
4769
chomp $fileHash ;
4754
4770
if (!($fileHash =~/ ^[0-9a-f]{40}$ / ))
4755
4771
{
@@ -4844,8 +4860,8 @@ sub lookupCommitRef
4844
4860
return $commitHash ;
4845
4861
}
4846
4862
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 ));
4849
4865
$commitHash =~s /\s *$// ;
4850
4866
if (!($commitHash =~/ ^[0-9a-f]{40}$ / ))
4851
4867
{
@@ -4854,7 +4870,7 @@ sub lookupCommitRef
4854
4870
4855
4871
if ( defined ($commitHash ) )
4856
4872
{
4857
- my $type = safe_pipe_capture(" git" ," cat-file" ," -t" ,$commitHash );
4873
+ my $type = :: safe_pipe_capture(" git" ," cat-file" ," -t" ,$commitHash );
4858
4874
if ( ! ($type =~/ ^commit\s *$ / ) )
4859
4875
{
4860
4876
$commitHash =undef ;
@@ -4907,7 +4923,7 @@ sub commitmessage
4907
4923
return $message ;
4908
4924
}
4909
4925
4910
- my @lines = safe_pipe_capture(" git" , " cat-file" , " commit" , $commithash );
4926
+ my @lines = :: safe_pipe_capture(" git" , " cat-file" , " commit" , $commithash );
4911
4927
shift @lines while ( $lines [0] =~ / \S / );
4912
4928
$message = join (" " ,@lines );
4913
4929
$message .= " " if ( $message =~ / \n $ / );
@@ -5056,25 +5072,6 @@ sub in_array
5056
5072
return $retval ;
5057
5073
}
5058
5074
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
-
5078
5075
=head2 mangle_dirname
5079
5076
5080
5077
create a string from a directory name that is suitable to use as
0 commit comments