| From 12e35d9a68323a6a294b15abc657046cafd5b1e4 Mon Sep 17 00:00:00 2001 |
| From: Junio C Hamano <gitster@pobox.com> |
| Date: Mon, 11 Sep 2017 14:44:24 +0900 |
| Subject: 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> |
| --- |
| git-cvsserver.perl | 47 ++++++++++++++++++++++------------------------- |
| 1 file changed, 22 insertions(+), 25 deletions(-) |
| |
| diff --git a/git-cvsserver.perl b/git-cvsserver.perl |
| index d50c85ed7b..8229d9d198 100755 |
| --- a/git-cvsserver.perl |
| +++ b/git-cvsserver.perl |
| @@ -3406,6 +3406,22 @@ sub refHashEqual |
| return $out; |
| } |
| |
| +# an alternative to `command` that allows input to be passed as an array |
| +# to work around shell problems with weird characters in arguments |
| + |
| +sub safe_pipe_capture { |
| + |
| + my @output; |
| + |
| + if (my $pid = open my $child, '-|') { |
| + @output = (<$child>); |
| + close $child or die join(' ',@_).": $! $?"; |
| + } else { |
| + exec(@_) or die "$! $?"; # exec() can fail the executable can't be found |
| + } |
| + return wantarray ? @output : join('',@output); |
| +} |
| + |
| |
| package GITCVS::log; |
| |
| @@ -3882,7 +3898,7 @@ sub update |
| # several candidate merge bases. let's assume |
| # that the first one is the best one. |
| my $base = eval { |
| - safe_pipe_capture('git', 'merge-base', |
| + ::safe_pipe_capture('git', 'merge-base', |
| $lastpicked, $parent); |
| }; |
| # The two branches may not be related at all, |
| @@ -4749,7 +4765,7 @@ sub getMetaFromCommithash |
| return $retVal; |
| } |
| |
| - my($fileHash)=safe_pipe_capture("git","rev-parse","$revCommit:$filename"); |
| + my($fileHash) = ::safe_pipe_capture("git","rev-parse","$revCommit:$filename"); |
| chomp $fileHash; |
| if(!($fileHash=~/^[0-9a-f]{40}$/)) |
| { |
| @@ -4844,8 +4860,8 @@ sub lookupCommitRef |
| return $commitHash; |
| } |
| |
| - $commitHash=safe_pipe_capture("git","rev-parse","--verify","--quiet", |
| - $self->unescapeRefName($ref)); |
| + $commitHash = ::safe_pipe_capture("git","rev-parse","--verify","--quiet", |
| + $self->unescapeRefName($ref)); |
| $commitHash=~s/\s*$//; |
| if(!($commitHash=~/^[0-9a-f]{40}$/)) |
| { |
| @@ -4854,7 +4870,7 @@ sub lookupCommitRef |
| |
| if( defined($commitHash) ) |
| { |
| - my $type=safe_pipe_capture("git","cat-file","-t",$commitHash); |
| + my $type = ::safe_pipe_capture("git","cat-file","-t",$commitHash); |
| if( ! ($type=~/^commit\s*$/ ) ) |
| { |
| $commitHash=undef; |
| @@ -4907,7 +4923,7 @@ sub commitmessage |
| return $message; |
| } |
| |
| - my @lines = safe_pipe_capture("git", "cat-file", "commit", $commithash); |
| + my @lines = ::safe_pipe_capture("git", "cat-file", "commit", $commithash); |
| shift @lines while ( $lines[0] =~ /\S/ ); |
| $message = join("",@lines); |
| $message .= " " if ( $message =~ /\n$/ ); |
| @@ -5056,25 +5072,6 @@ sub in_array |
| return $retval; |
| } |
| |
| -=head2 safe_pipe_capture |
| - |
| -an alternative to `command` that allows input to be passed as an array |
| -to work around shell problems with weird characters in arguments |
| - |
| -=cut |
| -sub safe_pipe_capture { |
| - |
| - my @output; |
| - |
| - if (my $pid = open my $child, '-|') { |
| - @output = (<$child>); |
| - close $child or die join(' ',@_).": $! $?"; |
| - } else { |
| - exec(@_) or die "$! $?"; # exec() can fail the executable can't be found |
| - } |
| - return wantarray ? @output : join('',@output); |
| -} |
| - |
| =head2 mangle_dirname |
| |
| create a string from a directory name that is suitable to use as |
| -- |
| 2.14.1.821.g8fa685d3b7 |
| |