From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B47EF1F4B4 for ; Wed, 31 Mar 2021 01:53:18 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei blob: "--mail" disables solver, use --include/only Date: Wed, 31 Mar 2021 06:53:18 +0500 Message-Id: <20210331015318.23535-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Assume a user specifying --mail doesn't want to spend cycles reconstructing a blob from a code repo. Also, don't require users to use add-external or a previous -I or --only to ready an external for use with ale.git. --- lib/PublicInbox/LeiBlob.pm | 18 +++++++++++++++--- t/solver_git.t | 21 +++++++++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/LeiBlob.pm b/lib/PublicInbox/LeiBlob.pm index 6195b368..ed0754a3 100644 --- a/lib/PublicInbox/LeiBlob.pm +++ b/lib/PublicInbox/LeiBlob.pm @@ -90,15 +90,25 @@ sub 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)}); + my $lxs; # first, see if it's a blob returned by "lei q" JSON output:k if ($opt->{mail} // ($has_hints ? 0 : 1)) { + if (grep(defined, @$opt{qw(include only)})) { + $lxs = $lei->lxs_prepare; + $lei->ale->refresh_externals($lxs); + } my $rdr = { 1 => $lei->{1} }; - open $rdr->{2}, '>', '/dev/null' or die "open: $!"; + if ($opt->{mail}) { + $rdr->{2} = $lei->{2}; + } else { + 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; + return $lei->child_error($?) if $opt->{mail}; } # maybe it's a non-email (code) blob from a coderepo @@ -108,7 +118,10 @@ sub lei_blob { unshift(@$git_dirs, $cgd) if defined $cgd; } return $lei->fail('no --git-dir to try') unless @$git_dirs; - my $lxs = $lei->lxs_prepare or return; + unless ($lxs) { + $lxs = $lei->lxs_prepare or return; + $lei->ale->refresh_externals($lxs); + } if ($lxs->remotes) { require PublicInbox::LeiRemote; $lei->{curl} //= which('curl') or return @@ -117,7 +130,6 @@ sub lei_blob { } require PublicInbox::SolverGit; my $self = bless { lxs => $lxs, oid_b => $blob }, __PACKAGE__; - $lei->ale; my ($op_c, $ops) = $lei->workers_start($self, 'lei_solve', 1, { '' => [ \&sol_done, $lei ] }); $lei->{sol} = $self; diff --git a/t/solver_git.t b/t/solver_git.t index 2d803d47..8acf907f 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -6,7 +6,8 @@ use v5.10.1; use PublicInbox::TestCommon; use Cwd qw(abs_path); require_git(2.6); -use Digest::SHA qw(sha1_hex); +use PublicInbox::ContentHash qw(git_sha); +use PublicInbox::Eml; use PublicInbox::Spawn qw(popen_rd which); require_mods(qw(DBD::SQLite Search::Xapian Plack::Util)); my $git_dir = xqx([qw(git rev-parse --git-dir)], undef, {2 => \(my $null)}); @@ -17,14 +18,15 @@ chomp $git_dir; $git_dir = abs_path($git_dir); use_ok "PublicInbox::$_" for (qw(Inbox V2Writable Git SolverGit WWW)); +my $patch2 = eml_load 't/solve/0002-rename-with-modifications.patch'; +my $patch2_oid = git_sha(1, $patch2)->hexdigest; my ($tmpdir, $for_destroy) = tmpdir(); my $ibx = create_inbox 'v2', version => 2, indexlevel => 'medium', sub { my ($im) = @_; $im->add(eml_load 't/solve/0001-simple-mod.patch') or BAIL_OUT; - $im->add(eml_load 't/solve/0002-rename-with-modifications.patch') or - BAIL_OUT; + $im->add($patch2) or BAIL_OUT; }; my $v1_0_0_tag = 'cb7c42b1e15577ed2215356a2bf925aef59cdd8d'; my $v1_0_0_tag_short = substr($v1_0_0_tag, 0, 16); @@ -32,8 +34,14 @@ my $expect = '69df7d565d49fbaaeb0a067910f03dc22cd52bd0'; my $non_existent = 'ee5e32211bf62ab6531bdf39b84b6920d0b6775a'; test_lei({tmpdir => $tmpdir}, sub { + lei_ok('blob', '--mail', $patch2_oid, '-I', $ibx->{inboxdir}, + \'--mail works for existing oid'); + is($lei_out, $patch2->as_string, 'blob matches'); + ok(!lei('blob', '--mail', '69df7d5', '-I', $ibx->{inboxdir}), + "--mail won't run solver"); + lei_ok('blob', '69df7d5', '-I', $ibx->{inboxdir}); - is(sha1_hex("blob ".length($lei_out)."\0".$lei_out), + is(git_sha(1, PublicInbox::Eml->new($lei_out))->hexdigest, $expect, 'blob contents output'); my $prev = $lei_out; lei_ok(qw(blob --no-mail 69df7d5 -I), $ibx->{inboxdir}); @@ -236,8 +244,9 @@ EOF test_lei({tmpdir => "$tmpdir/ext"}, sub { my $rurl = "$url/$name"; lei_ok(qw(blob --no-mail 69df7d5 -I), $rurl); - is(sha1_hex("blob ".length($lei_out)."\0".$lei_out), - $expect, 'blob contents output'); + my $eml = PublicInbox::Eml->new($lei_out); + is(git_sha(1, $eml)->hexdigest, $expect, + 'blob contents output'); ok(!lei(qw(blob -I), $rurl, $non_existent), 'non-existent blob fails'); });