The requests we make to git cat-file --batch are guaranteed to be
smaller than the 512 bytes required by PIPE_BUF, so there will be no
partial writes. Bypass Perl IO layers and write directly to the
pipe to avoid needing IO::Handle here.
use warnings;
use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC);
use POSIX qw(dup2);
use warnings;
use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC);
use POSIX qw(dup2);
sub new {
my ($class, $git_dir) = @_;
sub new {
my ($class, $git_dir) = @_;
close $out_r or die "close failed: $!\n";
close $in_w or die "close failed: $!\n";
close $out_r or die "close failed: $!\n";
close $in_w or die "close failed: $!\n";
$self->{in} = $in_r;
$self->{out} = $out_w;
$self->{pid} = $pid;
$self->{in} = $in_r;
$self->{out} = $out_w;
$self->{pid} = $pid;
sub cat_file {
my ($self, $object) = @_;
sub cat_file {
my ($self, $object) = @_;
+ $object .= "\n";
+ my $len = bytes::length($object);
+
- print { $self->{out} } $object, "\n" or die "write error: $!\n";
+ my $written = syswrite($self->{out}, $object);
+ if (!defined $written) {
+ die "pipe write error: $!\n";
+ } elsif ($written != $len) {
+ die "wrote too little to pipe ($written < $len)\n";
+ }
my $in = $self->{in};
my $head = <$in>;
my $in = $self->{in};
my $head = <$in>;