]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Git.pm
update copyrights for 2021
[public-inbox.git] / lib / PublicInbox / Git.pm
index 084069259110d26e8b043822c0c22ecc4a8a81d7..49c0d5d60760c7c3d0a7c2149df22fc4c53811bc 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
 # License: GPLv2 or later <https://www.gnu.org/licenses/gpl-2.0.txt>
 #
 # Used to read files from a git repository without excessive forking.
@@ -21,6 +21,7 @@ use PublicInbox::Tmpfile;
 use IO::Poll qw(POLLIN);
 use Carp qw(croak);
 use Digest::SHA ();
+use PublicInbox::DS qw(dwaitpid);
 our @EXPORT_OK = qw(git_unquote git_quote);
 our $PIPE_BUFSIZ = 65536; # Linux default
 our $in_cleanup;
@@ -125,6 +126,7 @@ sub _bidi_pipe {
        }
        my ($in_r, $p) = popen_rd(\@cmd, undef, $redir);
        $self->{$pid} = $p;
+       $self->{"$pid.owner"} = $$;
        $out_w->autoflush(1);
        if ($^O eq 'linux') { # 1031: F_SETPIPE_SZ
                fcntl($out_w, 1031, 4096);
@@ -326,10 +328,7 @@ sub _destroy {
 
        # GitAsyncCat::event_step may delete {pid}
        my $p = delete $self->{$pid} or return;
-
-       # PublicInbox::DS may not be loaded
-       eval { PublicInbox::DS::dwaitpid($p, undef, undef) };
-       waitpid($p, 0) if $@; # wait synchronously if not in event loop
+       dwaitpid($p) if $$ == $self->{"$pid.owner"};
 }
 
 sub cat_async_abort ($) {
@@ -362,10 +361,8 @@ sub popen {
 sub qx {
        my ($self, @cmd) = @_;
        my $fh = $self->popen(@cmd);
-       local $/ = "\n";
-       return <$fh> if wantarray;
-       local $/;
-       <$fh>
+       local $/ = wantarray ? "\n" : undef;
+       <$fh>;
 }
 
 # check_async and cat_async may trigger the other, so ensure they're