about summary refs log tree commit homepage
path: root/lib/PublicInbox/V2Writable.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-01-11 22:35:03 +0000
committerEric Wong <e@yhbt.net>2020-01-13 04:36:48 +0000
commitc5c709dcef1b5904467ff2aea3943f00a891dade (patch)
treee02f9d1e216c3beacc51d2ca43e5333c4dbd9f4f /lib/PublicInbox/V2Writable.pm
parenta208d17ed99577faa8b52d46107fad5516b346b0 (diff)
downloadpublic-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/V2Writable.pm')
-rw-r--r--lib/PublicInbox/V2Writable.pm11
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 51794326..9073d9ef 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -16,7 +16,7 @@ use PublicInbox::ContentId qw(content_id content_digest);
 use PublicInbox::Inbox;
 use PublicInbox::OverIdx;
 use PublicInbox::Msgmap;
-use PublicInbox::Spawn qw(spawn);
+use PublicInbox::Spawn qw(spawn popen_rd);
 use PublicInbox::SearchIdx;
 use IO::Handle; # ->autoflush
 use File::Temp qw(tempfile);
@@ -471,17 +471,12 @@ sub git_hash_raw ($$) {
         print $tmp_fh $$raw or die "print \$tmp_fh: $!";
         sysseek($tmp_fh, 0, 0) or die "seek failed: $!";
 
-        my ($r, $w);
-        pipe($r, $w) or die "failed to create pipe: $!";
-        my $rdr = { 0 => $tmp_fh, 1 => $w };
         my $git_dir = $self->{-inbox}->git->{git_dir};
         my $cmd = ['git', "--git-dir=$git_dir", qw(hash-object --stdin)];
-        my $pid = spawn($cmd, undef, $rdr);
-        close $w;
+        my $r = popen_rd($cmd, undef, { 0 => $tmp_fh });
         local $/ = "\n";
         chomp(my $oid = <$r>);
-        waitpid($pid, 0) == $pid or die "git hash-object did not finish";
-        die "git hash-object failed: $?" if $?;
+        close $r or die "git hash-object failed: $?";
         $oid =~ /\A[a-f0-9]{40}\z/ or die "OID not expected: $oid";
         $oid;
 }