From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7F7E81F69D for ; Tue, 28 Nov 2023 14:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1701183389; bh=YycJuSpMzZPoV2MjpW2mZdIK0cH5Gex9r5jUAaZrmps=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hqQowce/5r9KoLJedCmt7ndyIxhdUMVeMgdcbP5UzALoz1y4LNBEcDDkGIbB8Xuoj TeqjlADPUgPsMFZehZqT2vImxeDYtisP3VXGnWYlEGzTdGh8Y75Df7odAZwFirJboj fMS3HXTp4/hAzLZ2h5U1tpNSeELe2O+3DibLHq1o= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 10/14] cindex: require `-g GIT_DIR' or `-r PROJECT_ROOT' Date: Tue, 28 Nov 2023 14:56:23 +0000 Message-ID: <20231128145628.1455176-11-e@80x24.org> In-Reply-To: <20231128145628.1455176-1-e@80x24.org> References: <20231128145628.1455176-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Accepting @ARGV without switches ends up being ambiguous with optional parameters for --join and --show. Requiring users to specify `--join=' or `--show=' is a bit awkward (as it with -clone --objstore= and the like, but that is historical baggage we need to carry at this point...) --- Documentation/public-inbox-cindex.pod | 2 +- lib/PublicInbox/CodeSearchIdx.pm | 5 ++-- script/public-inbox-cindex | 38 ++++++++++++++++++--------- t/cindex-join.t | 7 ++++- t/cindex.t | 9 ++++--- t/xap_helper.t | 4 +-- 6 files changed, 42 insertions(+), 23 deletions(-) diff --git a/Documentation/public-inbox-cindex.pod b/Documentation/public-inbox-cindex.pod index 3ff394be..0c9c4bdb 100644 --- a/Documentation/public-inbox-cindex.pod +++ b/Documentation/public-inbox-cindex.pod @@ -4,7 +4,7 @@ public-inbox-cindex - create and update search for code repositories =head1 SYNOPSIS -public-inbox-cindex [OPTIONS] GIT_DIR... +public-inbox-cindex [OPTIONS] -g GIT_DIR [-g GIT_DIR] public-inbox-cindex [OPTIONS] --update diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm index a6cbe0b0..d49e9a8d 100644 --- a/lib/PublicInbox/CodeSearchIdx.pm +++ b/lib/PublicInbox/CodeSearchIdx.pm @@ -1131,8 +1131,6 @@ sub init_join_prefork ($) { } split(/,/, join(',', @$subopt)); require PublicInbox::CidxXapHelperAux; require PublicInbox::XapClient; - my $cfg = $self->{-opt}->{-pi_cfg} // die 'BUG: -pi_cfg unset'; - $self->{-cfg_f} = $cfg->{-f} = rel2abs_collapsed($cfg->{-f}); my @unknown; my $pfx = $JOIN{prefixes} // 'patchid'; for (split /\+/, $pfx) { @@ -1223,7 +1221,8 @@ sub cidx_run { # main entry point $PublicInbox::SearchIdx::BATCH_BYTES; local $MAX_SIZE = $self->{-opt}->{max_size}; local $self->{PENDING} = {}; # used by PublicInbox::CidxXapHelperAux - local $self->{-cfg_f}; + my $cfg = $self->{-opt}->{-pi_cfg} // die 'BUG: -pi_cfg unset'; + $self->{-cfg_f} = $cfg->{-f} = rel2abs_collapsed($cfg->{-f}); if (grep { $_ } @{$self->{-opt}}{qw(prune join)}) { require File::Temp; $TMPDIR = File::Temp->newdir('cidx-all-git-XXXX', TMPDIR => 1); diff --git a/script/public-inbox-cindex b/script/public-inbox-cindex index 97890c1b..a015d7a4 100755 --- a/script/public-inbox-cindex +++ b/script/public-inbox-cindex @@ -4,8 +4,8 @@ use v5.12; use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev); my $help = <{'project-list'})) { - my $pfx = shift @ARGV // die <{'project-list'})) { + my $pfx = $opt->{'project-root'} // die <{'git-dir'} and die <{'git-dir'}}) EOM open my $fh, '<', $pl or die "open($pl): $!\n"; chomp(@git_dirs = <$fh>); - $_ = PublicInbox::Admin::resolve_git_dir("$pfx/$_") for @git_dirs; + $pfx .= '/'; + $pfx =~ tr!/!/!s; + substr($_, 0, 0, $pfx) for @git_dirs; +} elsif (my $gd = $opt->{'git-dir'}) { + @git_dirs = @$gd; +} elsif (grep defined, @$opt{qw(show update prune)}) { } else { - @git_dirs = map { PublicInbox::Admin::resolve_git_dir($_) } @ARGV; + warn "No --git-dir= nor --project-list= + --project-root= specified\n"; + die $help; } + +$_ = PublicInbox::Admin::resolve_git_dir($_) for @git_dirs; if (defined $cidx_dir) { # external index die "`%' is not allowed in $cidx_dir\n" if $cidx_dir =~ /\%/; my $cidx = PublicInbox::CodeSearchIdx->new($cidx_dir, $opt); diff --git a/t/cindex-join.t b/t/cindex-join.t index ac90cd64..c2e85332 100644 --- a/t/cindex-join.t +++ b/t/cindex-join.t @@ -70,7 +70,7 @@ my $cidxdir = "$tmpdir/cidx"; my $rdr = { 1 => \my $cout, 2 => \my $cerr }; ok run_script([qw(-cindex -v --all --show=join_data), '--join=aggressive,dt:..2022-12-01', - '-d', $cidxdir, values %code ], + '-d', $cidxdir, map { ('-g', $_) } values %code ], $env, $rdr), 'initial join inboxes w/ coderepos'; my $out = PublicInbox::Config->json->decode($cout); is($out->{join_data}->{dt}->[0], '19700101'.'000000', @@ -79,4 +79,9 @@ is($out->{join_data}->{dt}->[0], '19700101'.'000000', ok run_script([qw(-cindex -v --all -u --join --show), '-d', $cidxdir], $env, $rdr), 'incremental --join'; +ok run_script([qw(-cindex -v --no-scan --show), + '-d', $cidxdir], $env, $rdr), 'show'; +$out = PublicInbox::Config->json->decode($cout); +is ref($out->{join_data}), 'HASH', 'got hash join data'; +is $cerr, '', 'no warnings or errors in stderr w/ --show'; done_testing; diff --git a/t/cindex.t b/t/cindex.t index 29d88ca8..0193cf18 100644 --- a/t/cindex.t +++ b/t/cindex.t @@ -33,7 +33,7 @@ git gc -q EOM }; # /create_coderepo -ok(run_script([qw(-cindex --dangerous -q), "$tmp/wt0"]), 'cindex internal'); +ok(run_script([qw(-cindex --dangerous -q -g), "$tmp/wt0"]), 'cindex internal'); { my $exists = -e "$tmp/wt0/.git/public-inbox-cindex/cidx.lock"; my @st = stat(_); @@ -67,13 +67,14 @@ git gc -q EOM }; # /create_coderepo -ok(run_script([qw(-cindex --dangerous -q -d), "$tmp/ext", $zp, "$tmp/wt0"]), +ok(run_script([qw(-cindex --dangerous -q -d), "$tmp/ext", + '-g', $zp, '-g', "$tmp/wt0" ]), 'cindex external'); ok(-e "$tmp/ext/cidx.lock", 'external dir created'); ok(!-d "$zp/.git/public-inbox-cindex", 'no cindex in original coderepo'); ok(run_script([qw(-cindex -L medium --dangerous -q -d), - "$tmp/med", $zp, "$tmp/wt0"]), 'cindex external medium'); + "$tmp/med", '-g', $zp, '-g', "$tmp/wt0"]), 'cindex external medium'); SKIP: { @@ -228,7 +229,7 @@ SKIP: { # --prune File::Path::remove_tree("$tmp/ext"); mkdir("$tmp/ext", 0707); -ok(run_script([qw(-cindex --dangerous -q -d), "$tmp/ext", $zp]), +ok(run_script([qw(-cindex --dangerous -q -d), "$tmp/ext", '-g', $zp]), 'external on existing dir'); { my @st = stat("$tmp/ext/cidx.lock"); diff --git a/t/xap_helper.t b/t/xap_helper.t index ee25b2dc..37679ae9 100644 --- a/t/xap_helper.t +++ b/t/xap_helper.t @@ -20,10 +20,10 @@ my $crepo = create_coderepo 'for-cindex', sub { xsys_e([qw(git init -q --bare)]); xsys_e([qw(git fast-import --quiet)], undef, { 0 => $fi_fh }); chdir($dh); - run_script([qw(-cindex --dangerous -L medium --no-fsync -q -j1), $d]) + run_script([qw(-cindex --dangerous -L medium --no-fsync -q -j1), '-g', $d]) or xbail '-cindex internal'; run_script([qw(-cindex --dangerous -L medium --no-fsync -q -j3 -d), - "$d/cidx-ext", $d]) or xbail '-cindex "external"'; + "$d/cidx-ext", '-g', $d]) or xbail '-cindex "external"'; }; $dh = $fi_fh = undef;