Skip to content

Commit f4c0035

Browse files
mina86gitster
authored andcommitted
Git.pm: allow pipes to be closed prior to calling command_close_bidi_pipe
The command_close_bidi_pipe() function will insist on closing both input and output pipes returned by command_bidi_pipe(). With this change it is possible to close one of the pipes in advance and pass undef as an argument. Signed-off-by: Michal Nazarewicz <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1323dba commit f4c0035

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

perl/Git.pm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,25 @@ Note that you should not rely on whatever actually is in C<CTX>;
426426
currently it is simply the command name but in future the context might
427427
have more complicated structure.
428428
429+
C<PIPE_IN> and C<PIPE_OUT> may be C<undef> if they have been closed prior to
430+
calling this function. This may be useful in a query-response type of
431+
commands where caller first writes a query and later reads response, eg:
432+
433+
my ($pid, $in, $out, $ctx) = $r->command_bidi_pipe('cat-file --batch-check');
434+
print $out "000000000\n";
435+
close $out;
436+
while (<$in>) { ... }
437+
$r->command_close_bidi_pipe($pid, $in, undef, $ctx);
438+
439+
This idiom may prevent potential dead locks caused by data sent to the output
440+
pipe not being flushed and thus not reaching the executed command.
441+
429442
=cut
430443

431444
sub command_close_bidi_pipe {
432445
local $?;
433446
my ($self, $pid, $in, $out, $ctx) = _maybe_self(@_);
434-
_cmd_close($ctx, $in, $out);
447+
_cmd_close($ctx, (grep { defined } ($in, $out)));
435448
waitpid $pid, 0;
436449
if ($? >> 8) {
437450
throw Git::Error::Command($ctx, $? >>8);

0 commit comments

Comments
 (0)