]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei blob: support --no-mail switch
authorEric Wong <e@80x24.org>
Sun, 28 Mar 2021 09:01:16 +0000 (09:01 +0000)
committerEric Wong <e@80x24.org>
Sun, 28 Mar 2021 23:01:36 +0000 (23:01 +0000)
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.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiBlob.pm
t/solver_git.t

index fdb0bbcf2fe1ffb1afb73ebea5abfae4b3a2a0d9..bad7fad94f1b195d896741be8cd4e74362bcb92a 100644 (file)
@@ -136,8 +136,8 @@ our %CMD = ( # sorted in order of importance/use:
        import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+), @c_opt,
        opt_dash('limit|n=i', '[0-9]+') ],
 
-'blob' => [ 'OID', 'display a git blob object, solving if necessary',
-       qw(git-dir=s@ cwd! verbose|v+ oid-a|A=s path-a|a=s path-b|b=s),
+'blob' => [ 'OID', 'show a git blob, reconstructing from mail if necessary',
+       qw(git-dir=s@ cwd! verbose|v+ mail! oid-a|A=s path-a|a=s path-b|b=s),
        @lxs_opt, @c_opt ],
 
 'add-external' => [ 'LOCATION',
index 9b4c4f30c7160fb95ef7c050396f3ca666c4ba79..4bd8625347396857dcf5d97faa82a9b06f6728fd 100644 (file)
@@ -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;
        }
index 22714ae574a10002bbc4e803fc6117543ffe6128..7bf3ba21d182c2d78cd54d17b28acc6d19504d47 100644 (file)
@@ -34,6 +34,9 @@ test_lei({tmpdir => $tmpdir}, sub {
        lei_ok('blob', '69df7d5', '-I', $ibx->{inboxdir});
        is(sha1_hex("blob ".length($lei_out)."\0".$lei_out),
                $expect, 'blob contents output');
+       my $prev = $lei_out;
+       lei_ok(qw(blob --no-mail 69df7d5 -I), $ibx->{inboxdir});
+       is($lei_out, $prev, '--no-mail works');
 
        # fallbacks
        lei_ok('blob', $v1_0_0_tag, '-I', $ibx->{inboxdir});