about summary refs log tree commit homepage
path: root/lib/PublicInbox/Git.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-02-27 21:31:24 +0000
committerEric Wong <e@80x24.org>2016-02-27 21:51:39 +0000
commit617f35dacbd4e5972bf2d82411b45009bbc79a42 (patch)
tree0a763db89c81941f16dbd16761a35602f3c723c9 /lib/PublicInbox/Git.pm
parentca885bd5905b7faa9ecb7b0eb02476de1d3a7f88 (diff)
downloadpublic-inbox-617f35dacbd4e5972bf2d82411b45009bbc79a42.tar.gz
This should reduce overhead of spawning git processes
from our long-running httpd and nntpd servers.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r--lib/PublicInbox/Git.pm16
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 5135862e..57d17d33 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -11,6 +11,7 @@ use strict;
 use warnings;
 use POSIX qw(dup2);
 require IO::Handle;
+use PublicInbox::Spawn qw(spawn popen_rd);
 
 sub new {
         my ($class, $git_dir) = @_;
@@ -26,13 +27,8 @@ sub _bidi_pipe {
         pipe($out_r, $out_w) or fail($self, "pipe failed: $!");
 
         my @cmd = ('git', "--git-dir=$self->{git_dir}", qw(cat-file), $batch);
-        $self->{$pid} = fork;
-        defined $self->{$pid} or fail($self, "fork failed: $!");
-        if ($self->{$pid} == 0) {
-                dup2(fileno($out_r), 0) or die "redirect stdin failed: $!\n";
-                dup2(fileno($in_w), 1) or die "redirect stdout failed: $!\n";
-                exec(@cmd) or die 'exec `' . join(' '). "' failed: $!\n";
-        }
+        my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) };
+        $self->{$pid} = spawn(\@cmd, undef, $redir);
         close $out_r or fail($self, "close failed: $!");
         close $in_w or fail($self, "close failed: $!");
         $out_w->autoflush(1);
@@ -123,12 +119,8 @@ sub fail {
 
 sub popen {
         my ($self, @cmd) = @_;
-        my $mode = '-|';
-        $mode = shift @cmd if ($cmd[0] eq '|-');
         @cmd = ('git', "--git-dir=$self->{git_dir}", @cmd);
-        my $pid = open my $fh, $mode, @cmd or
-                die('open `'.join(' ', @cmd) . " pipe failed: $!\n");
-        $fh;
+        popen_rd(\@cmd);
 }
 
 sub cleanup {