]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
(ext)index: move {max_size} and related bits to $self
authorEric Wong <e@80x24.org>
Fri, 10 Jan 2025 23:18:58 +0000 (23:18 +0000)
committerEric Wong <e@80x24.org>
Tue, 14 Jan 2025 04:45:34 +0000 (04:45 +0000)
`--max-size' is persistent for a process, so having it in $self
is more appropriate anyways than the shorter-lived $sync.  The
{index_oid} function pointer is tied to max-size handling, so
we'll move that over to $self as well.

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

index 2f6de2bbd2f75e8d2bc00eecbc24b588cb74e09d..ebcc8770edb4d31f5baced0eff14bd6ae0369630 100644 (file)
@@ -397,7 +397,8 @@ sub _sync_inbox ($$$) {
        if (defined(my $err = _ibx_index_reject($ibx))) {
                return "W: skipping $ekey ($err)";
        }
-       $sync->{ibx} = $ibx;
+       $sync->{ibx} = $ibx; # FIXME: eliminate
+       local $self->{ibx} = $ibx;
        $self->{nrec} = 0;
        my $v = $ibx->version;
        if ($v == 2) {
index 24f76c3299489ba38a431a9d59ac6eca3f991523..9771633d558697d7fda8b1777bc6c23e40b123ac 100644 (file)
@@ -849,12 +849,13 @@ sub index_sync {
 
 sub check_size { # check_async cb for -index --max-size=...
        my (undef, $oid, $type, $size, $arg) = @_;
+       my $self = $arg->{self};
        ($type // '') eq 'blob' or
-               die "E: bad $oid in $arg->{ibx}->{git}->{git_dir}";
-       if ($size <= $arg->{max_size}) {
-               $arg->{ibx}->{git}->cat_async($oid, $arg->{index_oid}, $arg);
+               die "E: bad $oid in $self->{ibx}->{git}->{git_dir}";
+       if ($size <= $self->{max_size}) {
+               $self->{ibx}->{git}->cat_async($oid, $self->{index_oid}, $arg);
        } else {
-               warn "W: skipping $oid ($size > $arg->{max_size})\n";
+               warn "W: skipping $oid ($size > $self->{max_size})\n";
        }
 }
 
@@ -921,16 +922,15 @@ sub v1_process_stack ($$$) {
                        $git->cat_async($oid, \&v1_unindex_both, $sync);
                }
        }
-       if ($sync->{max_size} = $self->{-opt}->{max_size}) {
-               $sync->{index_oid} = \&v1_index_both;
-       }
+       $self->{max_size} = $self->{-opt}->{max_size} and
+               $self->{index_oid} = \&v1_index_both;
        while (my ($f, $at, $ct, $oid, $cur_cmt) = $stk->pop_rec) {
                my $arg = { %$sync, cur_cmt => $cur_cmt, oid => $oid };
                last if $self->{quit};
                if ($f eq 'm') {
                        $arg->{autime} = $at;
                        $arg->{cotime} = $ct;
-                       if ($sync->{max_size}) {
+                       if ($self->{max_size}) {
                                $git->check_async($oid, \&check_size, $arg);
                        } else {
                                $git->cat_async($oid, \&v1_index_both, $arg);
index 886f59b1135dcc551f86b8d27deff482a5f3ad9a..ff4e973a108cf644095f0b188bb7bcc861917681 100644 (file)
@@ -935,9 +935,8 @@ sub sync_prepare ($$) {
                # rerun index_sync without {reindex}
                $reindex_heads = $self->last_commits($sync);
        }
-       if ($sync->{max_size} = $self->{-opt}->{max_size}) {
-               $sync->{index_oid} = $self->can('index_oid');
-       }
+       $self->{max_size} = $self->{-opt}->{max_size} and
+               $self->{index_oid} = $self->can('index_oid');
        my $git_pfx = "$sync->{ibx}->{inboxdir}/git";
        for (my $i = $sync->{epoch_max}; $i >= 0; $i--) {
                my $git_dir = "$git_pfx/$i.git";
@@ -1154,7 +1153,7 @@ sub index_todo ($$$) {
                        cur_cmt => $cmt
                };
                if ($f eq 'm') {
-                       if ($sync->{max_size}) {
+                       if ($self->{max_size}) {
                                $all->check_async($oid, \&check_size, $req);
                        } else {
                                $all->cat_async($oid, $index_oid, $req);