about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiBlob.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-28 09:01:16 +0000
committerEric Wong <e@80x24.org>2021-03-28 23:01:36 +0000
commit73e17de5421d83bedbf84209585cf2408b9af1ce (patch)
treebd598ceb87e83c05508f633080784eee8819c0e4 /lib/PublicInbox/LeiBlob.pm
parentc18c58eaeab19877d06146c365d300afdccc2a93 (diff)
downloadpublic-inbox-73e17de5421d83bedbf84209585cf2408b9af1ce.tar.gz
It's possible for a abbreviated OID to be resolved unambiguously
to an email before we attempt to look at externals via xsearch;
so provide a way for a user to force searching coderepos.

If hints (--oid-a, --path-a, --path-b) are present, we'll
assume --no-mail by default, otherwise we'll assume the
user wants to look through mail for a matching blob.
Diffstat (limited to 'lib/PublicInbox/LeiBlob.pm')
-rw-r--r--lib/PublicInbox/LeiBlob.pm23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/PublicInbox/LeiBlob.pm b/lib/PublicInbox/LeiBlob.pm
index 9b4c4f30..4bd86253 100644
--- a/lib/PublicInbox/LeiBlob.pm
+++ b/lib/PublicInbox/LeiBlob.pm
@@ -8,7 +8,6 @@ use v5.10.1;
 use parent qw(PublicInbox::IPC);
 use PublicInbox::Spawn qw(spawn popen_rd);
 use PublicInbox::DS;
-use PublicInbox::Eml;
 
 sub sol_done_wait { # dwaitpid callback
         my ($arg, $pid) = @_;
@@ -85,18 +84,22 @@ sub do_solve_blob { # via wq_do
 sub lei_blob {
         my ($lei, $blob) = @_;
         $lei->start_pager if -t $lei->{1};
+        my $opt = $lei->{opt};
+        my $has_hints = grep(defined, @$opt{qw(oid-a path-a path-b)});
 
-        # first, see if it's a blob returned by "lei q" JSON output:
-        my $rdr = { 1 => $lei->{1} };
-        open $rdr->{2}, '>', '/dev/null' or die "open: $!";
-        my $cmd = [ 'git', '--git-dir='.$lei->ale->git->{git_dir},
-                        'cat-file', 'blob', $blob ];
-        waitpid(spawn($cmd, $lei->{env}, $rdr), 0);
-        return if $? == 0;
+        # first, see if it's a blob returned by "lei q" JSON output:k
+        if ($opt->{mail} // ($has_hints ? 0 : 1)) {
+                my $rdr = { 1 => $lei->{1} };
+                open $rdr->{2}, '>', '/dev/null' or die "open: $!";
+                my $cmd = [ 'git', '--git-dir='.$lei->ale->git->{git_dir},
+                                'cat-file', 'blob', $blob ];
+                waitpid(spawn($cmd, $lei->{env}, $rdr), 0);
+                return if $? == 0;
+        }
 
         # maybe it's a non-email (code) blob from a coderepo
-        my $git_dirs = $lei->{opt}->{'git-dir'} //= [];
-        if ($lei->{opt}->{'cwd'} //= 1) {
+        my $git_dirs = $opt->{'git-dir'} //= [];
+        if ($opt->{'cwd'} // 1) {
                 my $cgd = get_git_dir('.');
                 unshift(@$git_dirs, $cgd) if defined $cgd;
         }