]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SolverGit.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / SolverGit.pm
index 610bd65b166c88489292a0c19224e034c2e4d5a6..38fba0ca79340eb655c12a319ab28d54621644fa 100644 (file)
@@ -82,7 +82,7 @@ sub solve_existing ($$) {
        my ($oid_full, $type, $size) = $git->check($oid_b);
 
        if ($oid_b eq ($oid_full // '') || (defined($type) &&
--                              (!$self->{have_hints} || $type eq 'blob'))) {
+                               (!$self->{have_hints} || $type eq 'blob'))) {
                delete $want->{try_gits};
                return [ $git, $oid_full, $type, int($size) ]; # done, success
        }
@@ -465,6 +465,7 @@ sub apply_result ($$) {
                        dbg($self, 'trying '.di_url($self, $nxt));
                        return do_git_apply($self);
                } else {
+                       $msg .= " (no patches left to try for $di->{oid_b})\n";
                        ERR($self, $msg);
                }
        } else {
@@ -486,15 +487,14 @@ sub do_git_apply ($) {
        my @cmd = (qw(git apply --cached --ignore-whitespace
                        --unidiff-zero --whitespace=warn --verbose));
        my $len = length(join(' ', @cmd));
-       my $total = $self->{tot};
        my $di; # keep track of the last one for "git ls-files"
        my $prv_oid_b;
 
        do {
                my $i = ++$self->{nr};
                $di = shift @$patches;
-               dbg($self, "\napplying [$i/$total] " . di_url($self, $di) .
-                       "\n" . $di->{hdr_lines});
+               dbg($self, "\napplying [$i/$self->{nr_p}] " .
+                       di_url($self, $di) . "\n" . $di->{hdr_lines});
                my $path = $di->{n};
                $len += length($path) + 1;
                push @cmd, $path;
@@ -555,8 +555,10 @@ sub extract_diffs_done {
        my $diffs = delete $self->{tmp_diffs};
        if (scalar @$diffs) {
                unshift @{$self->{patches}}, @$diffs;
-               dbg($self, "found $want->{oid_b} in " .  join(" ||\n\t",
-                       map { di_url($self, $_) } @$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:
@@ -638,7 +640,7 @@ sub resolve_patch ($$) {
 
        # scan through inboxes to look for emails which results in
        # the oid we want:
-       my $ibx = shift(@{$want->{try_ibxs}}) or die 'BUG: {try_ibxs} empty';
+       my $ibx = shift(@{$want->{try_ibxs}}) or return done($self, undef);
        if (my $msgs = find_smsgs($self, $ibx, $want)) {
                $want->{try_smsgs} = $msgs;
                $want->{cur_ibx} = $ibx;
@@ -653,14 +655,14 @@ sub resolve_patch ($$) {
 sub new {
        my ($class, $ibx, $user_cb, $uarg) = @_;
 
-       bless {
-               gits => $ibx->{-repo_objs},
+       bless { # $ibx is undef if coderepo only (see WwwCoderepo)
+               gits => $ibx ? $ibx->{-repo_objs} : undef,
                user_cb => $user_cb,
                uarg => $uarg,
                # -cur_di, -qsp_err, -msg => temp fields for Qspawn callbacks
 
                # TODO: config option for searching related inboxes
-               inboxes => [ $ibx ],
+               inboxes => $ibx ? [ $ibx ] : [],
        }, $class;
 }
 
@@ -679,7 +681,7 @@ sub solve ($$$$$) {
        $self->{oid_want} = $oid_want;
        $self->{out} = $out;
        $self->{seen_oid} = {};
-       $self->{tot} = 0;
+       $self->{tot} = $self->{nr_p} = 0;
        $self->{psgi_env} = $env;
        $self->{have_hints} = 1 if scalar keys %$hints;
        $self->{todo} = [ { %$hints, oid_b => $oid_want } ];