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 F21791F51B for ; Sun, 26 Nov 2023 14:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1701008374; bh=TTJYLSks44FnDsldh0QZgrsb6waBegHC8OnDGwY37KE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Bqic7cQs0bVGTJJMrhx0v4FZoevsq6zbzYd0O9kDCFMkKI/3FzowysDiwOOWe0AyP hc/3ODuMPeiWDb+kNAqYOqbti5oX8ldoDvsRLuRgyVvdyzVEYMUhPcypyxHpsCgyPR avHvSBP6MBX6l3OsFKLvlbiwNz3JfAEumQk0xis0= From: Eric Wong To: spew@80x24.org Subject: [PATCH 5/7] cindex: require `-g GIT_DIR' or `-r PROJECT_ROOT' Date: Sun, 26 Nov 2023 14:19:31 +0000 Message-ID: <20231126141933.593525-5-e@80x24.org> In-Reply-To: <20231126141933.593525-1-e@80x24.org> References: <20231126141933.593525-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 may be historical). --- Documentation/public-inbox-cindex.pod | 2 +- script/public-inbox-cindex | 34 +++++++++++++++++---------- t/cindex-join.t | 2 +- t/cindex.t | 9 +++---- 4 files changed, 29 insertions(+), 18 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/script/public-inbox-cindex b/script/public-inbox-cindex index 97890c1b..d615a8ca 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-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; -} else { - @git_dirs = map { PublicInbox::Admin::resolve_git_dir($_) } @ARGV; + $pfx .= '/'; + $pfx =~ tr!/!/!s; + substr($_, 0, 0, $pfx) for @git_dirs; +} elsif (my $gd = $opt->{'git-dir'}) { + @git_dirs = @$gd; +} elsif (@ARGV) { + my @g = map { "-g $_" } @ARGV; + die <new($cidx_dir, $opt); diff --git a/t/cindex-join.t b/t/cindex-join.t index 2836eb6c..8d0b09d2 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', diff --git a/t/cindex.t b/t/cindex.t index afcc226e..134df4ea 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");