From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E142020089 for ; Tue, 27 Oct 2020 07:54:57 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 26/52] v2writable: allow OO method references Date: Tue, 27 Oct 2020 07:54:27 +0000 Message-Id: <20201027075453.19163-27-e@80x24.org> In-Reply-To: <20201027075453.19163-1-e@80x24.org> References: <20201027075453.19163-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Using `->can(method)' allows subclasses to override `index_oid' and `unindex_oid' methods. --- lib/PublicInbox/V2Writable.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 7c7be1bd..c0306e82 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -1066,10 +1066,11 @@ sub sync_prepare ($$) { if (my @leftovers = keys %{delete($sync->{D}) // {}}) { warn('W: unindexing '.scalar(@leftovers)." leftovers\n"); my $arg = { v2w => $self }; + my $unindex_oid = $self->can('unindex_oid'); for my $oid (@leftovers) { $oid = unpack('H*', $oid); $self->{current_info} = "leftover $oid"; - $self->git->cat_async($oid, \&unindex_oid, $arg); + $self->git->cat_async($oid, $unindex_oid, $arg); } $self->git->cat_async_wait; } @@ -1139,9 +1140,10 @@ sub unindex_epoch ($$$$) { --no-notes --no-color --no-abbrev --no-renames); my $fh = $git->popen(@cmd, $unindex_range); local $sync->{in_unindex} = 1; + my $unindex_oid = $self->can('unindex_oid'); while (<$fh>) { /\A:\d{6} 100644 $OID ($OID) [AM]\tm$/o or next; - $self->git->cat_async($1, \&unindex_oid, $sync); + $self->git->cat_async($1, $unindex_oid, $sync); } close $fh or die "git log failed: \$?=$?"; $self->git->cat_async_wait; @@ -1211,17 +1213,19 @@ sub index_epoch ($$$) { defined(my $stk = $sync->{stacks}->[$i]) or return; $sync->{stacks}->[$i] = undef; my $all = $self->git; + my $index_oid = $self->can('index_oid'); + my $unindex_oid = $self->can('unindex_oid'); while (my ($f, $at, $ct, $oid) = $stk->pop_rec) { $self->{current_info} = "$i.git $oid"; + my $req = { %$sync, autime => $at, cotime => $ct, oid => $oid }; if ($f eq 'm') { - my $arg = { %$sync, autime => $at, cotime => $ct }; if ($sync->{max_size}) { - $all->check_async($oid, \&check_size, $arg); + $all->check_async($oid, \&check_size, $req); } else { - $all->cat_async($oid, \&index_oid, $arg); + $all->cat_async($oid, $index_oid, $req); } } elsif ($f eq 'd') { - $all->cat_async($oid, \&unindex_oid, $sync); + $all->cat_async($oid, $unindex_oid, $req); } if (${$sync->{need_checkpoint}}) { reindex_checkpoint($self, $sync); @@ -1308,7 +1312,7 @@ sub index_sync { } } if ($sync->{max_size} = $opt->{max_size}) { - $sync->{index_oid} = \&index_oid; + $sync->{index_oid} = $self->can('index_oid'); } # work forwards through history index_epoch($self, $sync, $_) for (0..$epoch_max);