]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/GitCatFile.pm
various internal documentation updates
[public-inbox.git] / lib / PublicInbox / GitCatFile.pm
index 48ae6734bbb23eb378dc84e1dd7c29be9bbe820f..dd95d5f3a0f94f5cd259cdffea4b98a6052d73e7 100644 (file)
@@ -1,5 +1,8 @@
 # Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
 # License: GPLv2 or later (https://www.gnu.org/licenses/gpl-2.0.txt)
+#
+# Used to read files from a git repository without excessive forking.
+# Used in our web interfaces as well as our -nntpd server.
 # This is based on code in Git.pm which is GPLv2, but modified to avoid
 # dependence on environment variables for compatibility with mod_perl.
 # There are also API changes to simplify our usage and data set.
@@ -7,10 +10,11 @@ package PublicInbox::GitCatFile;
 use strict;
 use warnings;
 use POSIX qw(dup2);
+require IO::Handle;
 
 sub new {
        my ($class, $git_dir) = @_;
-       bless { git_dir => $git_dir }, $class;
+       bless { git_dir => $git_dir }, $class
 }
 
 sub _cat_file_begin {
@@ -31,6 +35,7 @@ sub _cat_file_begin {
        }
        close $out_r or die "close failed: $!\n";
        close $in_w or die "close failed: $!\n";
+       $out_w->autoflush(1);
 
        $self->{in} = $in_r;
        $self->{out} = $out_w;
@@ -40,16 +45,8 @@ sub _cat_file_begin {
 sub cat_file {
        my ($self, $object, $sizeref) = @_;
 
-       $object .= "\n";
-       my $len = length($object);
-
        $self->_cat_file_begin;
-       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";
-       }
+       print { $self->{out} } $object, "\n" or die "pipe write error: $!\n";
 
        my $in = $self->{in};
        my $head = <$in>;