unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/3] cindex: handle usage errors gracefully
@ 2023-10-24 11:44 Eric Wong
  2023-10-24 11:44 ` [PATCH 1/3] cindex: --associate fails when no inboxes are given Eric Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Wong @ 2023-10-24 11:44 UTC (permalink / raw)
  To: meta

Eric Wong (3):
  cindex: --associate fails when no inboxes are given
  t/cindex: use autodie
  cindex: basic inboxes are non-fatal for --associate

 lib/PublicInbox/CodeSearchIdx.pm | 15 +++++++-------
 t/cindex.t                       | 34 ++++++++++++++++++++++++++------
 2 files changed, 36 insertions(+), 13 deletions(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] cindex: --associate fails when no inboxes are given
  2023-10-24 11:44 [PATCH 0/3] cindex: handle usage errors gracefully Eric Wong
@ 2023-10-24 11:44 ` Eric Wong
  2023-10-24 11:44 ` [PATCH 2/3] t/cindex: use autodie Eric Wong
  2023-10-24 11:44 ` [PATCH 3/3] cindex: basic inboxes are non-fatal for --associate Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2023-10-24 11:44 UTC (permalink / raw)
  To: meta

This functionality still needs to be fleshed out, but we
definitely can't associate coderepos to inboxes if we don't have
any inboxes as candidates.
---
 lib/PublicInbox/CodeSearchIdx.pm | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm
index 36d00aea..2d1d8b22 100644
--- a/lib/PublicInbox/CodeSearchIdx.pm
+++ b/lib/PublicInbox/CodeSearchIdx.pm
@@ -930,9 +930,8 @@ sub init_associate_postfork ($) {
 	require_progs('associate', join => \@JOIN);
 	$QRY_STR = $self->{-opt}->{'associate-date-range'} // '1.year.ago..';
 	substr($QRY_STR, 0, 0) = 'dt:';
-	scalar(@{$self->{git_dirs} //  []}) or die <<EOM;
-E: no coderepos to associate
-EOM
+	@{$self->{git_dirs} // []} or die "E: no coderepos to associate\n";
+	@IBX or die "E: no inboxes to associate\n";
 	my $approx_git = PublicInbox::Git->new($self->{git_dirs}->[0]); # ugh
 	$self->query_approxidate($approx_git, $QRY_STR); # in-place
 	$TODO{associate} = PublicInbox::OnDestroy->new($$, \&associate, $self);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] t/cindex: use autodie
  2023-10-24 11:44 [PATCH 0/3] cindex: handle usage errors gracefully Eric Wong
  2023-10-24 11:44 ` [PATCH 1/3] cindex: --associate fails when no inboxes are given Eric Wong
@ 2023-10-24 11:44 ` Eric Wong
  2023-10-24 11:44 ` [PATCH 3/3] cindex: basic inboxes are non-fatal for --associate Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2023-10-24 11:44 UTC (permalink / raw)
  To: meta

More tests to come, so cut down on the noise in the test code.
---
 t/cindex.t | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/t/cindex.t b/t/cindex.t
index dbbccbb0..51317329 100644
--- a/t/cindex.t
+++ b/t/cindex.t
@@ -5,6 +5,7 @@ use v5.12;
 use PublicInbox::TestCommon;
 use Cwd qw(getcwd abs_path);
 use List::Util qw(sum);
+use autodie qw(close open rename);
 require_mods(qw(json Xapian));
 use_ok 'PublicInbox::CodeSearchIdx';
 require PublicInbox::Import;
@@ -51,17 +52,17 @@ my $zp = create_coderepo 'NUL in patch', sub {
 	$src =~ s/\b(Limitation of Liability\.)\n\n/$1\n\0\n/s or
 		xbail "BUG: no `\\n\\n' in $pwd/COPYING";
 
-	open my $fh, '>', 'f' or xbail "open: $!";
+	open my $fh, '>', 'f';
 	print $fh $src or xbail "print: $!";
-	close $fh or xbail "close: $!";
+	close $fh;
 	xsys_e([qw(/bin/sh -c), <<'EOM']);
 git add f &&
 git commit -q -m 'initial with NUL character'
 EOM
 	$src =~ s/\n\0\n/\n\n/ or xbail "BUG: no `\\n\\0\\n'";
-	open $fh, '>', 'f' or xbail "open: $!";
+	open $fh, '>', 'f';
 	print $fh $src or xbail "print: $!";
-	close $fh or xbail "close: $!";
+	close $fh;
 	xsys_e([qw(/bin/sh -c), <<'EOM']);
 git add f &&
 git commit -q -m 'remove NUL character' &&
@@ -164,12 +165,12 @@ SKIP: { # --prune
 	my $csrch = PublicInbox::CodeSearch->new("$tmp/ext");
 	is(scalar($csrch->mset('s:hi')->items), 1, 'got hit');
 
-	rename("$tmp/wt0/.git", "$tmp/wt0/.giit") or xbail "rename $!";
+	rename("$tmp/wt0/.git", "$tmp/wt0/.giit");
 	ok(run_script([qw(-cindex -q --prune -d), "$tmp/ext"]), 'prune');
 	$csrch->reopen;
 	is(scalar($csrch->mset('s:hi')->items), 0, 'hit pruned');
 
-	rename("$tmp/wt0/.giit", "$tmp/wt0/.git") or xbail "rename $!";
+	rename("$tmp/wt0/.giit", "$tmp/wt0/.git");
 	ok(run_script([qw(-cindex -qu -d), "$tmp/ext"]), 'update');
 	$csrch->reopen;
 	is(scalar($csrch->mset('s:hi')->items), 0,

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] cindex: basic inboxes are non-fatal for --associate
  2023-10-24 11:44 [PATCH 0/3] cindex: handle usage errors gracefully Eric Wong
  2023-10-24 11:44 ` [PATCH 1/3] cindex: --associate fails when no inboxes are given Eric Wong
  2023-10-24 11:44 ` [PATCH 2/3] t/cindex: use autodie Eric Wong
@ 2023-10-24 11:44 ` Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2023-10-24 11:44 UTC (permalink / raw)
  To: meta

We need to gracefully continue when a user tries to associate
with --all but has basic (or completely unindexed) inboxes.
---
 lib/PublicInbox/CodeSearchIdx.pm | 10 ++++++----
 t/cindex.t                       | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm
index 2d1d8b22..c8e4c591 100644
--- a/lib/PublicInbox/CodeSearchIdx.pm
+++ b/lib/PublicInbox/CodeSearchIdx.pm
@@ -551,12 +551,14 @@ sub dump_roots_start {
 sub dump_ibx { # sends to xap_helper.h
 	my ($self, $ibx_id) = @_;
 	my $ibx = $IBX[$ibx_id] // die "BUG: no IBX[$ibx_id]";
-	my @cmd = ('dump_ibx', $ibx->isrch->xh_args,
-			(map { ('-A', $_) } @ASSOC_PFX),
-			$ibx_id, $QRY_STR);
+	my $ekey = $ibx->eidx_key;
+	my $srch = $ibx->isrch or return warn <<EOM;
+W: $ekey not indexed for search
+EOM
+	my @cmd = ('dump_ibx', $srch->xh_args,
+			(map { ('-A', $_) } @ASSOC_PFX), $ibx_id, $QRY_STR);
 	pipe(my $r, my $w);
 	$XHC->mkreq([$DUMP_IBX_WPIPE, $w], @cmd);
-	my $ekey = $ibx->eidx_key;
 	$self->{PENDING}->{$ekey} = $TODO{associate};
 	PublicInbox::CidxXapHelperAux->new($r, $self, $ekey);
 }
diff --git a/t/cindex.t b/t/cindex.t
index 51317329..c7de1505 100644
--- a/t/cindex.t
+++ b/t/cindex.t
@@ -198,4 +198,25 @@ SKIP: {
 	ok(run_script([qw(-xcpdb --compact), "$tmp/ext"]), 'xcpdb compact');
 };
 
+my $basic = create_inbox 'basic', indexlevel => 'basic', sub {
+	my ($im, $ibx) = @_;
+	$im->add(eml_load('t/plack-qp.eml'));
+};
+{
+	my $env = { PI_CONFIG => "$tmp/pi_config" };
+	open my $fh, '>', $env->{PI_CONFIG};
+	print $fh <<EOM;
+[publicinbox "basictest"]
+	inboxdir = $basic->{inboxdir}
+	address = basic\@example.com
+EOM
+	close $fh;
+	my $cmd = [ qw(-cindex -u --all --associate -d), "$tmp/ext",
+		'-I', $basic->{inboxdir} ];
+	my $opt = { 1 => \(my $cidx_out), 2 => \(my $cidx_err) };
+	ok(run_script($cmd, $env, $opt), 'associate w/o search');
+	like($cidx_err, qr/W: \Q$basic->{inboxdir}\E not indexed for search/,
+		'non-Xapian-enabled inbox noted');
+}
+
 done_testing;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-24 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 11:44 [PATCH 0/3] cindex: handle usage errors gracefully Eric Wong
2023-10-24 11:44 ` [PATCH 1/3] cindex: --associate fails when no inboxes are given Eric Wong
2023-10-24 11:44 ` [PATCH 2/3] t/cindex: use autodie Eric Wong
2023-10-24 11:44 ` [PATCH 3/3] cindex: basic inboxes are non-fatal for --associate Eric Wong

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).