cvsserver: move safe_pipe_capture() to the main package
As a preparation for replacing `command` with a call to this function from outside GITCVS::updater package, move it to the main package. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Sep 11, 2017 at 14:44 UTC
fce13af5d20cad8dcb2d0e47bcf01b6960f08e55
1 file changed
+22
-25
git-cvsserver.perl
+22
-25
@@ -3406,6 +3406,22 @@ sub refHashEqual
3406
return $out;
3407
}
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
+
3425
3426
package GITCVS::log;
3427
@@ -3882,7 +3898,7 @@ sub update
3898
# several candidate merge bases. let's assume
3899
# that the first one is the best one.
3900
my $base = eval {
3885
- safe_pipe_capture('git', 'merge-base',
3901
+ ::safe_pipe_capture('git', 'merge-base',
3902
$lastpicked, $parent);
3903
};
3904
# The two branches may not be related at all,
@@ -4749,7 +4765,7 @@ sub getMetaFromCommithash
4765
return $retVal;
4766
}
4767
4752
- my($fileHash)=safe_pipe_capture("git","rev-parse","$revCommit:$filename");
4768
+ my($fileHash) = ::safe_pipe_capture("git","rev-parse","$revCommit:$filename");
4769
chomp $fileHash;
4770
if(!($fileHash=~/^[0-9a-f]{40}$/))
4771
{
@@ -4844,8 +4860,8 @@ sub lookupCommitRef
4860
return $commitHash;
4861
}
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));
4865
$commitHash=~s/\s*$//;
4866
if(!($commitHash=~/^[0-9a-f]{40}$/))
4867
{
@@ -4854,7 +4870,7 @@ sub lookupCommitRef
4870
4871
if( defined($commitHash) )
4872
{
4857
- my $type=safe_pipe_capture("git","cat-file","-t",$commitHash);
4873
+ my $type = ::safe_pipe_capture("git","cat-file","-t",$commitHash);
4874
if( ! ($type=~/^commit\s*$/ ) )
4875
{
4876
$commitHash=undef;
@@ -4907,7 +4923,7 @@ sub commitmessage
4923
return $message;
4924
}
4925
4910
- my @lines = safe_pipe_capture("git", "cat-file", "commit", $commithash);
4926
+ my @lines = ::safe_pipe_capture("git", "cat-file", "commit", $commithash);
4927
shift @lines while ( $lines[0] =~ /\S/ );
4928
$message = join("",@lines);
4929
$message .= " " if ( $message =~ /\n$/ );
@@ -5056,25 +5072,6 @@ sub in_array
5072
return $retval;
5073
}
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
-
5075
=head2 mangle_dirname
5076
5077
create a string from a directory name that is suitable to use as