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,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF 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 D6D9C1F566 for ; Sun, 24 Sep 2023 05:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1695534134; bh=yCFjj6qzj81dFER7nY0Z3lcn0ABKW2V0kzMLoo9St98=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jk2WMQJpLtJDarScUM39rlIUhnGRtgT27lh8I9nsdKXCePI5CF+r/CacgV40JD4A3 tC1qTD/TEHZIF/qz9uPXHVrrwticF1Zl2sRdU6M9ZTZ/6yoguHkP3FnqMEOhWROZnU jwzkrfOAs+Ver2CC8UoCuRJa+wqygG1orTIuOMjY= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/6] config: handle key-only entries as booleans Date: Sun, 24 Sep 2023 05:42:11 +0000 Message-ID: <20230924054214.3539091-4-e@80x24.org> In-Reply-To: <20230924054214.3539091-1-e@80x24.org> References: <20230924054214.3539091-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: It's how git-config works, so our `git config --list' parser must be able to handle it. Fortunately this doesn't seem to incur a measurable overhead when parsing a config with 50k inboxes. --- lib/PublicInbox/Config.pm | 5 ++++- t/config.t | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 0a6b210f..f6236d84 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -151,8 +151,11 @@ sub config_fh_parse ($$$) { local $/ = $rs; while (defined($line = <$fh>)) { # perf critical with giant configs $i = index($line, $fs); + # $i may be -1 if $fs not found and it's a key-only entry + # (meaning boolean true). Either way the -1 will drop the + # $rs either from $k or $v. $k = substr($line, 0, $i); - $v = substr($line, $i + 1, -1); # chop off $fs + $v = $i >= 0 ? substr($line, $i + 1, -1) : 1; $section = substr($k, 0, rindex($k, '.')); $seen{$section} //= push(@section_order, $section); diff --git a/t/config.t b/t/config.t index 80f214cd..8a27a920 100644 --- a/t/config.t +++ b/t/config.t @@ -7,6 +7,25 @@ use_ok 'PublicInbox'; ok(defined(eval('$PublicInbox::VERSION')), 'VERSION defined'); use_ok 'PublicInbox::Config'; my ($tmpdir, $for_destroy) = tmpdir(); +use autodie qw(open close); +my $validate_git_behavior = $ENV{TEST_VALIDATE_GIT_BEHAVIOR}; + +{ + my $f = "$tmpdir/bool_config"; + open my $fh, '>', $f; + print $fh <git_config_dump($f); + $validate_git_behavior and + is(xqx([qw(git config -f), $f, qw(--bool imap.debug)]), + "true\n", 'git handles key-only as truth'); + ok($cfg->git_bool($cfg->{'imap.debug'}), 'key-only value handled'); + is($cfg->{'imap.port'}, 2, 'normal k=v read after key-only'); +} { PublicInbox::Import::init_bare($tmpdir);