about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-09-19 09:37:10 +0000
committerEric Wong <e@80x24.org>2020-09-19 21:39:44 +0000
commit7c0c47e26af17918031d449d24abe40ad452f51a (patch)
treefddbc502ebf93260eb078d8490729ef4260739f2 /lib
parent08259ae3cbc859aafa2a4bd79689b82b121ebf76 (diff)
downloadpublic-inbox-7c0c47e26af17918031d449d24abe40ad452f51a.tar.gz
This should be able to replace multiple `git cat-file' for blob
retrieval, but adjustments may be needed.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Gcf2Client.pm35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/PublicInbox/Gcf2Client.pm b/lib/PublicInbox/Gcf2Client.pm
new file mode 100644
index 00000000..71fbb1d1
--- /dev/null
+++ b/lib/PublicInbox/Gcf2Client.pm
@@ -0,0 +1,35 @@
+# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+package PublicInbox::Gcf2Client;
+use strict;
+use parent 'PublicInbox::Git';
+use PublicInbox::Spawn qw(popen_rd);
+use IO::Handle ();
+
+sub new {
+        my $self = shift->SUPER::new('/nonexistent');
+        my ($out_r, $out_w);
+        pipe($out_r, $out_w) or $self->fail("pipe failed: $!");
+        my $cmd = [ 'public-inbox-gcf2' ];
+        @$self{qw(in pid)} = popen_rd($cmd, undef, { 0 => $out_r });
+        $self->{inflight} = [];
+        $self->{out} = $out_w;
+        fcntl($out_w, 1031, 4096) if $^O eq 'linux'; # 1031: F_SETPIPE_SZ
+        $out_w->autoflush(1);
+        $self;
+}
+
+sub add_git_dir {
+        my ($self, $git_dir) = @_;
+
+        # ensure buffers are drained, length($git_dir) may exceed
+        # PIPE_BUF on platforms where PIPE_BUF is only 512 bytes
+        my $inflight = $self->{inflight};
+        while (scalar(@$inflight)) {
+                $self->cat_async_step($inflight);
+        }
+        print { $self->{out} } $git_dir, "\n" or
+                                $self->fail("write error: $!");
+}
+
+1;