about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-10-27 07:54:27 +0000
committerEric Wong <e@80x24.org>2020-11-07 10:19:00 +0000
commit0e8186eb863daf05e71c35549aaff890b4709c65 (patch)
tree816eb6d958219db7e356e944d394d267a42bbfe6
parentcef0b6e8d43a0dbd918bb0811dfe5c1bc337cc7c (diff)
downloadpublic-inbox-0e8186eb863daf05e71c35549aaff890b4709c65.tar.gz
Using `->can(method)' allows subclasses to override `index_oid'
and `unindex_oid' methods.
-rw-r--r--lib/PublicInbox/V2Writable.pm18
1 files 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);