From: Eric Wong Date: Fri, 10 Jan 2025 23:18:11 +0000 (+0000) Subject: (ext)index: move {latest_cmt} to $self (from $sync) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=896c2b94aafc659dbe17327d6f32ad17e6f89f74;p=thirdparty%2Fpublic-inbox.git (ext)index: move {latest_cmt} to $self (from $sync) No more sigil and brace overload from ${$sync->{latest_cmt}} and another step towards $sync elimination. --- diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index 21f6b33a7..441bb7b0d 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -271,7 +271,7 @@ sub do_finalize ($) { } # cur_cmt may be undef for unindex_oid, set by V2Writable::index_todo if (defined(my $cur_cmt = $req->{cur_cmt})) { - ${$req->{latest_cmt}} = $cur_cmt; + $req->{self}->{latest_cmt} = $cur_cmt; } } @@ -342,7 +342,7 @@ sub cur_ibx_xnum ($$;$) { sub index_oid { # git->cat_async callback for 'm' my ($bref, $oid, $type, $size, $req) = @_; - my $self = $req->{self}; + my $self = $req->{self} // die 'BUG: {self} missing'; local $self->{current_info} = "$self->{current_info} $oid"; return if is_bad_blob($oid, $type, $size, $req->{oid}); my $new_smsg = $req->{new_smsg} = bless { @@ -354,7 +354,7 @@ sub index_oid { # git->cat_async callback for 'm' $req->{xnum} = cur_ibx_xnum($req, $bref, $mismatch) // do { warn "# deleted\n"; warn "# mismatch $_->{blob}\n" for @$mismatch; - ${$req->{latest_cmt}} = $req->{cur_cmt} // + $self->{latest_cmt} = $req->{cur_cmt} // die "BUG: {cur_cmt} unset ($oid)\n"; return; }; @@ -531,6 +531,7 @@ sub eidx_gc { # top-level entry point local $self->{need_checkpoint} = 0; local $self->{nrec}; local $self->{-opt} = $opt; + local $self->{latest_cmt}; my $sync = { self => $self }; $self->idx_init($opt); # acquire lock via V2Writable::_idx_init eidx_gc_scan_inboxes($self, $sync); @@ -1119,6 +1120,7 @@ sub eidx_sync { # main entry point local $self->{nrec} = 0; local $self->{-opt} = $opt; local $self->{-regen_fmt} = "%u/?\n"; + local $self->{latest_cmt}; my $sync = { # DO NOT SET {reindex} here, it's incompatible with reused # V2Writable code, reindex is totally different here @@ -1166,7 +1168,7 @@ sub eidx_sync { # main entry point sub update_last_commit { # overrides V2Writable my ($self, $sync, $stk) = @_; my $unit = $sync->{unit} // return; - my $latest_cmt = $stk ? $stk->{latest_cmt} : ${$sync->{latest_cmt}}; + my $latest_cmt = $stk ? $stk->{latest_cmt} : $self->{latest_cmt}; defined($latest_cmt) or return; my $ibx = $sync->{ibx} or die 'BUG: {ibx} missing'; my $ekey = $ibx->eidx_key; diff --git a/lib/PublicInbox/IdxStack.pm b/lib/PublicInbox/IdxStack.pm index 7681ee6f1..8816d96b0 100644 --- a/lib/PublicInbox/IdxStack.pm +++ b/lib/PublicInbox/IdxStack.pm @@ -14,7 +14,7 @@ use PublicInbox::IO qw(read_all); sub new { open(my $io, '+>', undef); # latest_cmt is still useful when the newest revision is a `d'(elete), - # otherwise we favor $sync->{latest_cmt} for checkpoints and {quit} + # otherwise we favor $self->{latest_cmt} for checkpoints and {quit} bless { wr => $io, latest_cmt => $_[1] }, __PACKAGE__ } diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 628a1469c..6a8769633 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -813,7 +813,7 @@ sub index_both { # git->cat_async callback ++$self->{nidx}; ++$self->{nrec}; my $cur_cmt = $sync->{cur_cmt} // die 'BUG: {cur_cmt} missing'; - ${$sync->{latest_cmt}} = $cur_cmt; + $self->{latest_cmt} = $cur_cmt; } sub unindex_both { # git->cat_async callback @@ -824,7 +824,7 @@ sub unindex_both { # git->cat_async callback unindex_eml($self, $oid, PublicInbox::Eml->new($bref)); # may be undef if leftover if (defined(my $cur_cmt = $sync->{cur_cmt})) { - ${$sync->{latest_cmt}} = $cur_cmt; + $self->{latest_cmt} = $cur_cmt; } ++$self->{nidx}; } @@ -865,7 +865,7 @@ sub v1_checkpoint ($$;$) { $self->{need_checkpoint} = 0; # $newest may be undef - my $newest = $stk ? $stk->{latest_cmt} : ${$sync->{latest_cmt}}; + my $newest = $stk ? $stk->{latest_cmt} : $self->{latest_cmt}; if (defined($newest)) { my $cur = $self->{mm}->last_commit; if (need_update($self, $sync, $cur, $newest)) { @@ -912,7 +912,7 @@ sub process_stack { $self->{nrec} = 0; $sync->{sidx} = $self; local $self->{need_checkpoint} = 0; - $sync->{latest_cmt} = \(my $latest_cmt); + local $self->{latest_cmt}; $self->{mm}->{dbh}->begin_work; if (my @leftovers = keys %{delete($sync->{D}) // {}}) { diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index ca231e0c5..e5dae5485 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -723,7 +723,7 @@ sub index_finalize ($$) { my ($arg, $index) = @_; ++$arg->{self}->{nidx}; if (defined(my $cur = $arg->{cur_cmt})) { - ${$arg->{latest_cmt}} = $cur; + $arg->{self}->{latest_cmt} = $cur; } elsif ($index) { die 'BUG: {cur_cmt} missing'; } # else { unindexing @leftovers doesn't set {cur_cmt} @@ -819,7 +819,7 @@ sub index_oid { # cat_async callback sub update_last_commit { my ($self, $sync, $stk) = @_; my $unit = $sync->{unit} // return; - my $latest_cmt = $stk ? $stk->{latest_cmt} : ${$sync->{latest_cmt}}; + my $latest_cmt = $stk ? $stk->{latest_cmt} : $self->{latest_cmt}; defined($latest_cmt) or return; my $last = last_epoch_commit($self, $unit->{epoch}); if (defined $last && is_ancestor($self->git, $last, $latest_cmt)) { @@ -1137,7 +1137,7 @@ sub index_todo ($$$) { $pfx //= $unit->{git}->{git_dir}; } local $self->{current_info} = "$pfx "; - local $sync->{latest_cmt} = \(my $latest_cmt); + local $self->{latest_cmt}; local $sync->{unit} = $unit; while (my ($f, $at, $ct, $oid, $cmt) = $stk->pop_rec) { if ($sync->{quit}) {