]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-gcf2
gcf2: transparently retry on missing OID
[public-inbox.git] / script / public-inbox-gcf2
1 #!perl -w
2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 eval { require PublicInbox::Gcf2 };
5 die "libgit2 development package or Inline::C missing for $0: $@\n" if $@;
6 my @dirs; # may get big (30K-100K)
7 my $gcf2 = PublicInbox::Gcf2::new();
8 use IO::Handle; # autoflush
9 STDERR->autoflush(1);
10 STDOUT->autoflush(1);
11
12 while (<STDIN>) {
13         chomp;
14         if (m!\A/!) { # +/path/to/git-dir
15                 push @dirs, $_;
16                 $gcf2->add_alternate("$_/objects");
17         } elsif (!$gcf2->cat_oid(1, $_)) {
18                 # retry once if missing.  We only get unabbreviated OIDs
19                 # from SQLite or Xapian DBs, here, so malicious clients
20                 # can't trigger excessive retries:
21                 my $oid = $_;
22                 warn "I: $$ $oid missing, retrying...\n";
23
24                 # clients may need to wait a bit for this:
25                 $gcf2 = PublicInbox::Gcf2::new();
26                 $gcf2->add_alternate("$_/objects") for @dirs;
27
28                 if ($gcf2->cat_oid(1, $oid)) {
29                         warn "I: $$ $oid found after retry\n";
30                 } else {
31                         warn "W: $$ $oid missing after retry\n";
32                         print "$oid missing\n"; # mimic git-cat-file
33                 }
34         }
35 }