user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] lei blob: "--mail" disables solver, use --include/only
@ 2021-03-31  1:53 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-03-31  1:53 UTC (permalink / raw)
  To: meta

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-31  1:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31  1:53 [PATCH] lei blob: "--mail" disables solver, use --include/only Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git