diff options
author | Eric Wong <e@yhbt.net> | 2020-01-11 22:35:03 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-01-13 04:36:48 +0000 |
commit | c5c709dcef1b5904467ff2aea3943f00a891dade (patch) | |
tree | e02f9d1e216c3beacc51d2ca43e5333c4dbd9f4f /lib/PublicInbox/Git.pm | |
parent | a208d17ed99577faa8b52d46107fad5516b346b0 (diff) | |
download | public-inbox-c5c709dcef1b5904467ff2aea3943f00a891dade.tar.gz |
popen_rd accepts arbitrary redirects, so we can reuse its code to setup the pipe end we want to read, saving each caller a few lines of code compared to calling pipe+spawn.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r-- | lib/PublicInbox/Git.pm | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 15f53495..4f230197 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -12,7 +12,7 @@ use warnings; use POSIX qw(dup2); use IO::Handle; # ->autoflush use File::Glob qw(bsd_glob GLOB_NOSORT); -use PublicInbox::Spawn qw(spawn popen_rd); +use PublicInbox::Spawn qw(popen_rd); use PublicInbox::Tmpfile; use base qw(Exporter); our @EXPORT_OK = qw(git_unquote git_quote); @@ -104,27 +104,24 @@ sub _bidi_pipe { } return; } - my ($in_r, $in_w, $out_r, $out_w); - - pipe($in_r, $in_w) or fail($self, "pipe failed: $!"); + my ($out_r, $out_w); pipe($out_r, $out_w) or fail($self, "pipe failed: $!"); - if ($^O eq 'linux') { # 1031: F_SETPIPE_SZ - fcntl($out_w, 1031, 4096); - fcntl($in_w, 1031, 4096) if $batch eq '--batch-check'; - } - my @cmd = (qw(git), "--git-dir=$self->{git_dir}", qw(-c core.abbrev=40 cat-file), $batch); - my $redir = { 0 => $out_r, 1 => $in_w }; + my $redir = { 0 => $out_r }; if ($err) { my $id = "git.$self->{git_dir}$batch.err"; my $fh = tmpfile($id) or fail($self, "tmpfile($id): $!"); $self->{$err} = $fh; $redir->{2} = $fh; } - my $p = spawn(\@cmd, undef, $redir); + my ($in_r, $p) = popen_rd(\@cmd, undef, $redir); $self->{$pid} = $p; $out_w->autoflush(1); + if ($^O eq 'linux') { # 1031: F_SETPIPE_SZ + fcntl($out_w, 1031, 4096); + fcntl($in_r, 1031, 4096) if $batch eq '--batch-check'; + } $self->{$out} = $out_w; $self->{$in} = $in_r; } |