user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] lei blob: "--mail" disables solver, use --include/only
Date: Wed, 31 Mar 2021 06:53:18 +0500	[thread overview]
Message-ID: <20210331015318.23535-1-e@80x24.org> (raw)

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');
 		});

                 reply	other threads:[~2021-03-31  1:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210331015318.23535-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).