From: Eric Wong Date: Sat, 18 Jan 2025 01:26:13 +0000 (+0000) Subject: config: config_fh_parse: hardcode FS/RS X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=98fdfdc9a186b1ec9c4a30b0371174d0e752fbee;p=thirdparty%2Fpublic-inbox.git config: config_fh_parse: hardcode FS/RS We no longer need the flexibility to handle non-NUL-delimited output from `git config -l', so simplify callers and allow a theoretically sufficiently-advanced Perl implementation optimize more easily. Followup-to: 21146412 (config: drop scalar ref support from internal API, 2023-09-24) --- diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 358ddd2a2..03db2a51a 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -139,15 +139,15 @@ sub default_file { $ENV{PI_CONFIG} // (config_dir() . '/config'); } -sub config_fh_parse ($$$) { - my ($fh, $rs, $fs) = @_; +sub config_fh_parse ($) { + my ($fh) = @_; my (%rv, %seen, @section_order, $line, $k, $v, $section, $cur, $i); - local $/ = $rs; + local $/ = "\0"; 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 + $i = index($line, "\n"); + # $i may be -1 if "\n" isn't found and it's a key-only entry # (meaning boolean true). Either way the -1 will drop the - # $rs either from $k or $v. + # "\n" either from $k or $v. $k = substr($line, 0, $i); $v = $i >= 0 ? substr($line, $i + 1, -1) : 1; $section = substr($k, 0, rindex($k, '.')); @@ -195,7 +195,7 @@ sub git_config_dump { my @cmd = (git_exe, @opt_c, qw(config -z -l --includes)); push(@cmd, '-f', $file) if !@opt_c && defined($file); my $fh = popen_rd(\@cmd, \%env, $opt); - my $rv = config_fh_parse($fh, "\0", "\n"); + my $rv = config_fh_parse $fh; $fh->close or die "@cmd failed: \$?=$?\n"; $rv->{-opt_c} = \@opt_c if @opt_c; # for ->urlmatch $rv->{-f} = $file; diff --git a/lib/PublicInbox/LeiViewText.pm b/lib/PublicInbox/LeiViewText.pm index fa608ca2b..9ab01ffb5 100644 --- a/lib/PublicInbox/LeiViewText.pm +++ b/lib/PublicInbox/LeiViewText.pm @@ -8,6 +8,7 @@ use strict; use v5.10.1; use PublicInbox::MsgIter qw(msg_part_text); use PublicInbox::MID qw(references); +use PublicInbox::Config; use PublicInbox::View; use PublicInbox::Hval; use PublicInbox::ViewDiff; @@ -75,7 +76,7 @@ sub new { return $self unless $self->{color} //= -t $lei->{1}; my @cmd = (git_exe, qw(config -z --includes -l)); # reuse normal git cfg my $r = popen_rd(\@cmd, undef, { 2 => $lei->{2} }); - my $cfg = PublicInbox::Config::config_fh_parse($r, "\0", "\n"); + my $cfg = PublicInbox::Config::config_fh_parse $r; if (!$r->close) { warn "# @cmd failed, no color (non-fatal \$?=$?)\n"; return $self;