]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SolverGit.pm
run update-copyrights from gnulib for 2019
[public-inbox.git] / lib / PublicInbox / SolverGit.pm
index 463a9b6906ba069f87a049ea7f4fc40a51334153..58869ffb3677c66432dbcebe9a7ea6684db9dc07 100644 (file)
@@ -13,7 +13,6 @@ use warnings;
 use File::Temp qw();
 use Fcntl qw(SEEK_SET);
 use PublicInbox::Git qw(git_unquote git_quote);
-use PublicInbox::Spawn qw(spawn popen_rd);
 use PublicInbox::MsgIter qw(msg_iter msg_part_text);
 use PublicInbox::Qspawn;
 use URI::Escape qw(uri_escape_utf8);
@@ -62,14 +61,15 @@ sub ERR ($$) {
        die $err;
 }
 
-# look for existing blobs already in git repos
+# look for existing objects already in git repos
 sub solve_existing ($$) {
        my ($self, $want) = @_;
        my $oid_b = $want->{oid_b};
+       my $have_hints = scalar keys %$want > 1;
        my @ambiguous; # Array of [ git, $oids]
        foreach my $git (@{$self->{gits}}) {
                my ($oid_full, $type, $size) = $git->check($oid_b);
-               if (defined($type) && $type eq 'blob') {
+               if (defined($type) && (!$have_hints || $type eq 'blob')) {
                        return [ $git, $oid_full, $type, int($size) ];
                }
 
@@ -84,7 +84,8 @@ sub solve_existing ($$) {
                # push @ambiguous, [ $git, @oids ];
 
                dbg($self, "`$oid_b' ambiguous in " .
-                               join("\n\t", $git->pub_urls) . "\n" .
+                               join("\n\t", $git->pub_urls($self->{psgi_env}))
+                                . "\n" .
                                join('', map { "$_ blob\n" } @oids));
        }
        scalar(@ambiguous) ? \@ambiguous : undef;
@@ -204,7 +205,7 @@ sub find_extract_diff ($$$) {
        }
 
        my $msgs = $srch->query($q, { relevance => 1 });
-       my $re = qr/\Aindex ($pre[a-f0-9]*)\.\.($post[a-f0-9]*)(?: (\d+))?/;
+       my $re = qr/\Aindex ($pre[a-f0-9]*)\.\.($post[a-f0-9]*)(?: ([0-9]+))?/;
 
        my $di;
        foreach my $smsg (@$msgs) {
@@ -480,10 +481,11 @@ sub resolve_patch ($$) {
                die "Loop detected solving $cur_want\n";
        }
        if (my $existing = solve_existing($self, $want)) {
+               my ($found_git, undef, $type, undef) = @$existing;
                dbg($self, "found $cur_want in " .
-                       join("\n", $existing->[0]->pub_urls));
+                       join("\n", $found_git->pub_urls($self->{psgi_env})));
 
-               if ($cur_want eq $self->{oid_want}) { # all done!
+               if ($cur_want eq $self->{oid_want} || $type ne 'blob') {
                        eval { delete($self->{user_cb})->($existing) };
                        die "E: $@" if $@;
                        return;
@@ -540,6 +542,7 @@ sub new {
 }
 
 # recreate $oid_want using $hints
+# hints keys: path_a, path_b, oid_a
 # Calls {user_cb} with: [ ::Git object, oid_full, type, size, di (diff_info) ]
 # with found object, or undef if nothing was found
 # Calls {user_cb} with a string error on fatal errors