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-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,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 829302142A for ; Mon, 21 Jan 2019 20:52:57 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 17/37] solver: simplify control flow for initial loop Date: Mon, 21 Jan 2019 20:52:33 +0000 Message-Id: <20190121205253.10455-18-e@80x24.org> In-Reply-To: <20190121205253.10455-1-e@80x24.org> References: <20190121205253.10455-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 70d8a93..beafa42 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) { -- EW