]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
searchidx: quiet down old git patchid
authorEric Wong <e@80x24.org>
Fri, 15 Dec 2023 20:22:46 +0000 (15:22 -0500)
committerEric Wong <e@80x24.org>
Sat, 16 Dec 2023 10:06:29 +0000 (10:06 +0000)
CentOS 7.x ships with git 1.8.5, so unless a CentOS 7.x user
enables 3rd-party repos[1], they'll be stuck with a version
of git without `--stable' (though I'm becoming skeptical of
indexing patchids at all).

[1] https://public-inbox.org/meta/20210421151308.yz5hzkgm75klunpe@nitro.local/

lib/PublicInbox/SearchIdx.pm

index 1ac8e33e005c83642f62e6e2a8a3731fcb1f94f8..1cbf6d235a16a53646c9cb04cc39d4a9d031f7d8 100644 (file)
@@ -44,6 +44,7 @@ my $hex = '[a-f0-9]';
 my $OID = $hex .'{40,}';
 my @VMD_MAP = (kw => 'K', L => 'L'); # value order matters
 our $INDEXLEVELS = qr/\A(?:full|medium|basic)\z/;
+our $PATCHID_BROKEN;
 
 sub new {
        my ($class, $ibx, $creat, $shard) = @_;
@@ -63,6 +64,7 @@ sub new {
                        die("Invalid indexlevel $ibx->{indexlevel}\n");
                }
        }
+       undef $PATCHID_BROKEN; # retry on new instances in case of upgrades
        $ibx = PublicInbox::InboxWritable->new($ibx);
        my $self = PublicInbox::Search->new($ibx);
        bless $self, $class;
@@ -353,7 +355,8 @@ sub index_diff ($$$) {
 sub index_body_text {
        my ($self, $doc, $sref) = @_;
        my $rd;
-       if ($$sref =~ /^(?:diff|---|\+\+\+) /ms) { # start patch-id in parallel
+       # start patch-id in parallel
+       if ($$sref =~ /^(?:diff|---|\+\+\+) /ms && !$PATCHID_BROKEN) {
                my $git = ($self->{ibx} // $self->{eidx} // $self)->git;
                my $fh = PublicInbox::IO::write_file '+>:utf8', undef, $$sref;
                $fh->flush or die "flush: $!";
@@ -386,7 +389,12 @@ sub index_body_text {
        if (defined $rd) { # reap `git patch-id'
                (readline($rd) // '') =~ /\A([a-f0-9]{40,})/ and
                        $doc->add_term('XDFID'.$1);
-               $rd->close or warn "W: git patch-id failed: \$?=$? (non-fatal)"
+               if (!$rd->close) {
+                       my $c = 'git patch-id --stable';
+                       $PATCHID_BROKEN = ($? >> 8) == 129;
+                       $PATCHID_BROKEN ? warn("W: $c requires git v2.1.0+\n")
+                               : warn("W: $c failed: \$?=$? (non-fatal)");
+               }
        }
 }