]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
solver: fix and improve ambiguous OID debug messages
authorEric Wong <e@80x24.org>
Mon, 9 Dec 2024 20:01:28 +0000 (20:01 +0000)
committerEric Wong <e@80x24.org>
Tue, 10 Dec 2024 18:11:11 +0000 (18:11 +0000)
Ambiguous messages from git start with "hint:" (at least
nowadays) so we need to account for that in the regexp.
Furthermore, do not limit objects to just blobs since our
ViewVCS package is capable of displaying tags, trees, and
commits in addition to blobs.

Finally, we can generate full URLs so linkification can pick
them up and generate <a> tags.

lib/PublicInbox/SolverGit.pm

index d50a2fd1c0a8a11bf6adbf69caeb3dd65000ab6f..d9465771116bfd0a94bd385d97f1b0dcc289645f 100644 (file)
@@ -107,18 +107,21 @@ sub ck_existing_cb { # async_check cb
 
        # parse stderr of "git cat-file --batch-check", async means
        # we may end up slurping output from other requests:
-       my $err = $git->last_check_err;
-       my $prev_oids = $git->{-prev_oids} //= [];
-       my @any_oids = ($err =~ /\b([a-f0-9]{40,})\s+blob\b/g);
-       push @$prev_oids, @any_oids;
-       my $oid_b_re = qr/\A$want->{oid_b}/;
-       my @ambig_oids = grep /$oid_b_re/, @$prev_oids;
-       @$prev_oids = grep !/$oid_b_re/, @$prev_oids;
-       delete $git->{-prev_oids} unless @$prev_oids;
-       @ambig_oids and dbg($self, "`$want->{oid_b}' ambiguous in " .
-                       join("\n\t", $git->pub_urls($self->{psgi_env}))
-                       . "\n" .
-                       join('', map { "$_ blob\n" } @ambig_oids));
+       my @err = grep /\s+(?:[a-f0-9]{7,})\s+(?:blob|commit|tree|tag)\b/g,
+                       split /^/ms, $git->last_check_err;
+       my $prev = $git->{-prev} //= [];
+       push @$prev, @err;
+       my $oid_b_re = qr/\s+\Q$want->{oid_b}\E[a-f0-9]*\s+/;
+       my $ambig = join '', grep /$oid_b_re/, @$prev;
+       @$prev = grep !/$oid_b_re/, @$prev;
+       delete $git->{-prev} unless @$prev;
+       if ($ambig ne '') {
+               my @urls = $git->pub_urls($self->{psgi_env});
+               rindex($urls[0], '/') >= 0 and
+                       $ambig =~ s!\b([a-f0-9]{7,})\b!$urls[0]$1/s/!g;
+               dbg($self, "`$want->{oid_b}' ambiguous in " .
+                       join("\n\t", @urls) . "\n" .  $ambig);
+       }
 
        return retry_current($self, $want) if @$try;