]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
config: config_fh_parse: hardcode FS/RS
authorEric Wong <e@80x24.org>
Sat, 18 Jan 2025 01:26:13 +0000 (01:26 +0000)
committerEric Wong <e@80x24.org>
Tue, 21 Jan 2025 22:37:02 +0000 (22:37 +0000)
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)
lib/PublicInbox/Config.pm
lib/PublicInbox/LeiViewText.pm

index 358ddd2a20e907f61c60cc31a2f9495931b41375..03db2a51a25cd0bf88e6dcb347fe9fbd759b934b 100644 (file)
@@ -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;
index fa608ca2bc69881440fb9870b45ea5e9b4d417a5..9ab01ffb5ed68062de6281ad2587e367b59ce244 100644 (file)
@@ -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;