diff options
author | Eric Wong <e@yhbt.net> | 2020-07-17 07:25:07 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-07-17 20:56:55 +0000 |
commit | 340652d9833d9b7de4724a721e7014bfed262ccf (patch) | |
tree | 4ab07df02930b542553a40f3ad8d1b72bad56c25 /lib/PublicInbox | |
parent | 592f8239dceb6604e538fd51e62bcce50d6e1972 (diff) | |
download | public-inbox-340652d9833d9b7de4724a721e7014bfed262ccf.tar.gz |
We can rely on FD_CLOEXEC being set by default (since Perl 5.6+) on pipes to avoid FS/page-cache traffic, here. We also know "git hash-object" won't output anything until it's consumed all of its standard input; so there's no danger of a deadlock even in the the unlikely case git uses a hash that can't fit into PIPE_BUF :P
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/V2Writable.pm | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index dffe90d8..0582dd5e 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -482,14 +482,12 @@ sub purge { sub git_hash_raw ($$) { my ($self, $raw) = @_; # grab the expected OID we have to reindex: - open my $tmp_fh, '+>', undef or die "failed to open tmp: $!"; - $tmp_fh->autoflush(1); - print $tmp_fh $$raw or die "print \$tmp_fh: $!"; - sysseek($tmp_fh, 0, 0) or die "seek failed: $!"; - + pipe(my($in, $w)) or die "pipe: $!"; my $git_dir = $self->{-inbox}->git->{git_dir}; my $cmd = ['git', "--git-dir=$git_dir", qw(hash-object --stdin)]; - my $r = popen_rd($cmd, undef, { 0 => $tmp_fh }); + my $r = popen_rd($cmd, undef, { 0 => $in }); + print $w $$raw or die "print \$w: $!"; + close $w or die "close \$w: $!"; local $/ = "\n"; chomp(my $oid = <$r>); close $r or die "git hash-object failed: $?"; |