From 0412b5fd8b5e98e4967a0f210cfb2b922ed59d43 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 19 Jan 2019 05:44:12 +0000 Subject: solver: simplify control flow for initial loop We'll be breaking this up into several steps, too; since searching inboxes for patch blobs can take 10s of milliseconds for me. --- lib/PublicInbox/SolverGit.pm | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm index 70d8a934..beafa42d 100644 --- a/lib/PublicInbox/SolverGit.pm +++ b/lib/PublicInbox/SolverGit.pm @@ -361,11 +361,13 @@ sub solve ($$$$) { my @todo = ($req); my $found = {}; # { abbrev => [ ::Git, oid_full, type, size, $di ] } my $patches = []; # [ array of $di hashes ] - - my $max = $self->{max_steps} || 200; - my $steps = 0; + my $max = $self->{max_patches} || 200; while (defined(my $want = pop @todo)) { + if (scalar(@$patches) > $max) { + print $out "Aborting, too many steps to $oid_b\n"; + return; + } # see if we can find the blob in an existing git repo: my $want_oid = $want->{oid_b}; if (my $existing = solve_existing($self, $out, $want)) { @@ -373,9 +375,8 @@ sub solve ($$$$) { join("\n", $existing->[0]->pub_urls), "\n"; return $existing if $want_oid eq $oid_b; # DONE! - $found->{$want_oid} = $existing; - next; # ok, one blob resolved, more to go? + last; # ok, one blob resolved, more to go? } # scan through inboxes to look for emails which results in @@ -390,21 +391,12 @@ sub solve ($$$$) { # good, we can find a path to the oid we $want, now # lets see if we need to apply more patches: my $src = $di->{oid_a}; - if ($src !~ /\A0+\z/) { - if (++$steps > $max) { - print $out -"Aborting, too many steps to $oid_b\n"; - return; - } + last if $src =~ /\A0+\z/; - # we have to solve it using another oid, fine: - my $job = { - oid_b => $src, - path_b => $di->{path_a}, - }; - push @todo, $job; - } + # we have to solve it using another oid, fine: + my $job = { oid_b => $src, path_b => $di->{path_a} }; + push @todo, $job; last; # onto the next @todo item } unless ($di) { -- cgit v1.2.3-24-ge0c7