From: Eric Wong Date: Wed, 25 Oct 2023 00:29:46 +0000 (+0000) Subject: cindex: use run_await to read extensions.objectFormat X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=709fcf00c4d52a66c03190cd152f35bb9815e4e1;p=thirdparty%2Fpublic-inbox.git cindex: use run_await to read extensions.objectFormat This saves us the trouble of seeking ourselves by using existing run_await functionality. We'll also be more robust to ensure we only handle the result if the `git config' process exited without a signal. --- diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm index c1ab569c1..68b47d026 100644 --- a/lib/PublicInbox/CodeSearchIdx.pm +++ b/lib/PublicInbox/CodeSearchIdx.pm @@ -829,20 +829,18 @@ sub prep_umask ($) { } } -sub prep_alternate_end { # awaitpid callback for config extensions.objectFormat - my ($pid, $objdir, $out, $run_prune) = @_; - my $status = $? >> 8; +sub prep_alternate_end { # run_await cb for config extensions.objectFormat + my ($pid, $cmd, undef, $opt, $objdir, $run_prune) = @_; + my ($status, $sig) = ($? >> 8, $? & 127); my $next_dir = shift(@PRUNE_QUEUE); prep_alternate_start($next_dir, $run_prune) if defined($next_dir); my $fmt; - if ($status == 1) { # unset, default is '' (SHA-1) + if (!$sig && $status == 1) { # unset, default is '' (SHA-1) $fmt = 'sha1'; - } elsif ($status == 0) { - seek($out, 0, SEEK_SET); - chomp($fmt = <$out> // 'sha1'); - } else { - return warn("git config \$?=$? for objdir=$objdir"); + } elsif (!$sig && $status == 0) { + chomp($fmt = ${$opt->{1}} || 'sha1'); } + $fmt // return warn("git config \$?=$? for objdir=$objdir"); my $hexlen = $OFMT2HEXLEN{$fmt} // return warn <', $f; + open $ALT_FH{$hexlen}, '>', "$git_dir/objects/info/alternates"; } say { $ALT_FH{$hexlen} } $objdir or die "say: $!"; } @@ -865,9 +862,7 @@ sub prep_alternate_start { } my $cmd = [ 'git', "--git-dir=$git_dir", qw(config extensions.objectFormat) ]; - open my $out, '+>', undef; - my $pid = spawn($cmd, undef, { 1 => $out }); - awaitpid($pid, \&prep_alternate_end, $o, $out, $run_prune); + run_await($cmd, undef, undef, \&prep_alternate_end, $o, $run_prune); } sub cmd_done { # run_await cb for sort, xapian-delve, sed failures