]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
(ext)index: move {latest_cmt} to $self (from $sync)
authorEric Wong <e@80x24.org>
Fri, 10 Jan 2025 23:18:11 +0000 (23:18 +0000)
committerEric Wong <e@80x24.org>
Tue, 14 Jan 2025 04:45:28 +0000 (04:45 +0000)
No more sigil and brace overload from ${$sync->{latest_cmt}}
and another step towards $sync elimination.

lib/PublicInbox/ExtSearchIdx.pm
lib/PublicInbox/IdxStack.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/V2Writable.pm

index 21f6b33a7a22498d53946a0aca0d01de2f716dd3..441bb7b0da5e22a44c8de0580e5b389b61639e8d 100644 (file)
@@ -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;
index 7681ee6f17fe263730328f4e6f1e830a7f5a688d..8816d96b0ec4e5ee80b66c54be4b269d3a306ee5 100644 (file)
@@ -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__
 }
 
index 628a1469c48943714148f7597e82ea83367884f9..6a8769633564b60edaa68b4752573e47c2766070 100644 (file)
@@ -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}) // {}}) {
index ca231e0c53fae72a354ce253150cab1d5aaf27f2..e5dae5485b871a364a0e5a9749f396faba7a149c 100644 (file)
@@ -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}) {