+sub retry_current {
+ my ($self, $want) = @_;
+ push @{$self->{todo}}, $want;
+ next_step($self); # retry solve_existing
+}
+
+sub try_harder ($$) {
+ my ($self, $want) = @_;
+
+ # do we have more inboxes to try?
+ return retry_current($self, $want) if scalar @{$want->{try_ibxs}};
+
+ my $cur_want = $want->{oid_b};
+ if (length($cur_want) > $OID_MIN) { # maybe a shorter OID will work
+ delete $want->{try_ibxs}; # drop empty arrayref
+ chop($cur_want);
+ dbg($self, "retrying $want->{oid_b} as $cur_want");
+ $want->{oid_b} = $cur_want;
+ return retry_current($self, $want); # retry with shorter abbrev
+ }
+
+ dbg($self, "could not find $cur_want");
+ eval { done($self, undef) };
+ die "E: $@" if $@;
+}
+
+sub extract_diffs_done {
+ my ($self, $want) = @_;
+
+ delete $want->{try_smsgs};
+ delete $want->{cur_ibx};
+
+ my $diffs = delete $self->{tmp_diffs};
+ if (scalar @$diffs) {
+ unshift @{$self->{patches}}, @$diffs;
+ my %seen; # List::Util::uniq requires Perl 5.26+ :<
+ my @u = grep { !$seen{$_}++ } map { di_url($self, $_) } @$diffs;
+ dbg($self, "found $want->{oid_b} in " . join(" ||\n\t", @u));
+ ++$self->{nr_p};
+
+ # good, we can find a path to the oid we $want, now
+ # lets see if we need to apply more patches:
+ my $di = $diffs->[0];
+ my $src = $di->{oid_a};
+
+ unless ($src =~ /\A0+\z/) {
+ # we have to solve it using another oid, fine:
+ my $job = { oid_b => $src, path_b => $di->{path_a} };
+ push @{$self->{todo}}, $job;
+ }
+ return next_step($self); # onto the next todo item
+ }
+ try_harder($self, $want);
+}
+
+sub extract_diff_async {
+ my ($bref, $oid, $type, $size, $x) = @_;
+ my ($self, $want, $smsg) = @$x;
+ if (defined($oid)) {
+ $smsg->{blob} eq $oid or
+ ERR($self, "BUG: $smsg->{blob} != $oid");
+ PublicInbox::Eml->new($bref)->each_part(\&extract_diff, $x, 1);
+ }
+
+ scalar(@{$want->{try_smsgs}}) ? retry_current($self, $want)
+ : extract_diffs_done($self, $want);
+}
+