]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/Gcf2Client.pm
gcf2: transparently retry on missing OID
[public-inbox.git] / lib / PublicInbox / Gcf2Client.pm
1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 package PublicInbox::Gcf2Client;
4 use strict;
5 use parent 'PublicInbox::Git';
6 use PublicInbox::Spawn qw(popen_rd);
7 use IO::Handle ();
8
9 sub new {
10         my ($rdr) = @_;
11         my $self = bless {}, __PACKAGE__;
12         my ($out_r, $out_w);
13         pipe($out_r, $out_w) or $self->fail("pipe failed: $!");
14         $rdr //= {};
15         $rdr->{0} = $out_r;
16         @$self{qw(in pid)} = popen_rd(['public-inbox-gcf2'], undef, $rdr);
17         $self->{inflight} = [];
18         $self->{out} = $out_w;
19         fcntl($out_w, 1031, 4096) if $^O eq 'linux'; # 1031: F_SETPIPE_SZ
20         $out_w->autoflush(1);
21         $self;
22 }
23
24 sub add_git_dir {
25         my ($self, $git_dir) = @_;
26
27         # ensure buffers are drained, length($git_dir) may exceed
28         # PIPE_BUF on platforms where PIPE_BUF is only 512 bytes
29         my $inflight = $self->{inflight};
30         while (scalar(@$inflight)) {
31                 $self->cat_async_step($inflight);
32         }
33         print { $self->{out} } $git_dir, "\n" or
34                                 $self->fail("write error: $!");
35 }
36
37 # always false, since -gcf2 retries internally
38 sub alternates_changed {}
39
40 1;