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 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 F03BD1FC59 for ; Sat, 10 Aug 2024 09:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1723280414; bh=5eQn6fegjvtzZYcpoes1JLgk2fz7oZowa7qeVkBb/fE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iKv53s6vKL64Gyk2m3VcQ/7DzY1U5b+2W9u0A0fM7GbDUYAabqNa5O6lsLyZUV+WC JKCeXB7WGkR9OxvBCurEBKWMe7Mu9yBvSipgGc9O46v+cKKc+wj10HgQKsgLJ70ugi WXaGe434z8l9GsoxLdXI8OwvQwLGS1xsSwIo9vVs= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/11] search: help: avoid ':' in user prefixes Date: Sat, 10 Aug 2024 09:00:04 +0000 Message-ID: <20240810090012.23269-4-e@80x24.org> In-Reply-To: <20240810090012.23269-1-e@80x24.org> References: <20240810090012.23269-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: The non-':'-suffixed variation of the string is already used as hash keys and literals elsewhere. Theoretically, a Perl implementation can save some allocations this way (though Perl 5 currently doesn't). In any case, we'll introduce a help2txt method to allow sharing code between the callers in WwwText and Documentation/common.perl --- Documentation/common.perl | 22 ++--------- lib/PublicInbox/AltId.pm | 2 +- lib/PublicInbox/IndexHeader.pm | 2 +- lib/PublicInbox/Isearch.pm | 2 +- lib/PublicInbox/Search.pm | 71 ++++++++++++++++++++-------------- lib/PublicInbox/WwwText.pm | 25 +----------- 6 files changed, 49 insertions(+), 75 deletions(-) diff --git a/Documentation/common.perl b/Documentation/common.perl index 3a6617c4..53bae495 100755 --- a/Documentation/common.perl +++ b/Documentation/common.perl @@ -3,7 +3,7 @@ # License: AGPL-3.0+ use strict; use Fcntl qw(SEEK_SET); -my $have_search = eval { require PublicInbox::Search; 1 }; +use PublicInbox::Search; my $addr = 'meta@public-inbox.org'; for my $pod (@ARGV) { open my $fh, '+<', $pod or die "open($pod): $!"; @@ -27,7 +27,7 @@ L =head1$1 !ms; - $have_search and $s =~ s!^=for\scomment\n + $s =~ s!^=for\scomment\n ^AUTO-GENERATED-SEARCH-TERMS-BEGIN\n .+? ^=for\scomment\n @@ -46,23 +46,7 @@ L } sub search_terms { - my $help = eval('\@PublicInbox::Search::HELP'); - my $s = ''; - my $pad = 0; - my $i; - for ($i = 0; $i < @$help; $i += 2) { - my $pfx = $help->[$i]; - my $n = length($pfx); - $pad = $n if $n > $pad; - $s .= $pfx . "\0"; - $s .= $help->[$i + 1]; - $s .= "\f\n"; - } - $pad += 2; - my $padding = ' ' x ($pad + 4); - $s =~ s/^/$padding/gms; - $s =~ s/^$padding(\S+)\0/" $1".(' ' x ($pad - length($1)))/egms; - $s =~ s/\f\n/\n/gs; + my $s = PublicInbox::Search::help2txt(@PublicInbox::Search::HELP); $s =~ s/^ //gms; substr($s, 0, 0, "=for comment\nAUTO-GENERATED-SEARCH-TERMS-BEGIN\n\n"); $s .= "\n=for comment\nAUTO-GENERATED-SEARCH-TERMS-END\n"; diff --git a/lib/PublicInbox/AltId.pm b/lib/PublicInbox/AltId.pm index bd6cf973..76dc23e6 100644 --- a/lib/PublicInbox/AltId.pm +++ b/lib/PublicInbox/AltId.pm @@ -56,7 +56,7 @@ sub index_extra { # for PublicInbox::SearchIdx sub user_help { # for PublicInbox::Search my ($self) = @_; - ("$self->{prefix}:", <{prefix}, <{prefix}:12345 (boolean) EOF } diff --git a/lib/PublicInbox/IndexHeader.pm b/lib/PublicInbox/IndexHeader.pm index 07827959..a67080f9 100644 --- a/lib/PublicInbox/IndexHeader.pm +++ b/lib/PublicInbox/IndexHeader.pm @@ -62,7 +62,7 @@ sub index_extra { # for PublicInbox::SearchIdx sub user_help { # for PublicInbox::Search my ($self) = @_; - ("$self->{prefix}:", <{prefix}, <{header}' mail header e.g. $self->{prefix}:stable EOF } diff --git a/lib/PublicInbox/Isearch.pm b/lib/PublicInbox/Isearch.pm index 20808d6d..9566f710 100644 --- a/lib/PublicInbox/Isearch.pm +++ b/lib/PublicInbox/Isearch.pm @@ -131,7 +131,7 @@ sub mset_to_smsg { sub has_threadid { 1 } -sub help { $_[0]->{es}->help } +sub help_txt { $_[0]->{es}->help_txt } sub xh_args { # prep getopt args to feed to xap_helper.h socket my ($self, $opt) = @_; # TODO uid_range diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 6a0bdb0f..bdf5591c 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -190,33 +190,33 @@ my %prob_prefix = ( # especially since we don't offer boolean searches for To/Cc/From # headers, either our @HELP = ( - 's:' => 'match within Subject e.g. s:"a quick brown fox"', - 'd:' => < 'match within Subject e.g. s:"a quick brown fox"', + d => < 'match within message body, including text attachments', - 'nq:' => 'match non-quoted text within message body', - 'q:' => 'match quoted text within message body', - 'n:' => 'match filename of attachment(s)', - 't:' => 'match within the To header', - 'c:' => 'match within the Cc header', - 'f:' => 'match within the From header', - 'a:' => 'match within the To, Cc, and From headers', - 'tc:' => 'match within the To and Cc headers', - 'l:' => 'match contents of the List-Id header', - 'bs:' => 'match within the Subject and body', - 'dfn:' => 'match filename from diff', - 'dfa:' => 'match diff removed (-) lines', - 'dfb:' => 'match diff added (+) lines', - 'dfhh:' => 'match diff hunk header context (usually a function name)', - 'dfctx:' => 'match diff context lines', - 'dfpre:' => 'match pre-image git blob ID', - 'dfpost:' => 'match post-image git blob ID', - 'dfblob:' => 'match either pre or post-image git blob ID', - 'patchid:' => "match `git patch-id --stable' output", - 'rt:' => < 'match within message body, including text attachments', + nq => 'match non-quoted text within message body', + q => 'match quoted text within message body', + n => 'match filename of attachment(s)', + t => 'match within the To header', + c => 'match within the Cc header', + f => 'match within the From header', + a => 'match within the To, Cc, and From headers', + tc => 'match within the To and Cc headers', + l => 'match contents of the List-Id header', + bs => 'match within the Subject and body', + dfn => 'match filename from diff', + dfa => 'match diff removed (-) lines', + dfb => 'match diff added (+) lines', + dfhh => 'match diff hunk header context (usually a function name)', + dfctx => 'match diff context lines', + dfpre => 'match pre-image git blob ID', + dfpost => 'match post-image git blob ID', + dfblob => 'match either pre or post-image git blob ID', + patchid => "match `git patch-id --stable' output", + rt => < $pad; + $htxt .= $pfx . ":\0" . shift(@help) . "\f\n"; + } + $pad += 2; + my $padding = ' ' x ($pad + 4); + $htxt =~ s/^/$padding/gms; + $htxt =~ s/^$padding(\S+)\0/" $1".(' ' x ($pad - length($1)))/egms; + $htxt =~ s/\f\n/\n/gs; + $htxt; +} + +sub help_txt { my ($self) = @_; $self->{qp} // $self->qparse_new; # parse altids + indexheaders - my @ret = @HELP; - if (my $user_pfx = $self->{-user_pfx}) { - push @ret, @$user_pfx; - } - \@ret; + help2txt(@HELP, @{$self->{-user_pfx} // []}); } # always returns a scalar value diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm index 8279591a..d39083b6 100644 --- a/lib/PublicInbox/WwwText.pm +++ b/lib/PublicInbox/WwwText.pm @@ -75,29 +75,6 @@ sub get_text { PublicInbox::WwwStream::html_oneshot($ctx, $code, $txt); } -sub _srch_prefix ($$) { - my ($ibx, $txt) = @_; - my $pad = 0; - my $htxt = ''; - my $help = $ibx->isrch->help; - my $i; - for ($i = 0; $i < @$help; $i += 2) { - my $pfx = $help->[$i]; - my $n = length($pfx); - $pad = $n if $n > $pad; - $htxt .= $pfx . "\0"; - $htxt .= $help->[$i + 1]; - $htxt .= "\f\n"; - } - $pad += 2; - my $padding = ' ' x ($pad + 4); - $htxt =~ s/^/$padding/gms; - $htxt =~ s/^$padding(\S+)\0/" $1".(' ' x ($pad - length($1)))/egms; - $htxt =~ s/\f\n/\n/gs; - $$txt .= $htxt; - 1; -} - sub _colors_help ($$) { my ($ctx, $txt) = @_; my $ibx = $ctx->{ibx}; @@ -461,7 +438,7 @@ search Prefixes supported in this installation include: EOF - _srch_prefix($ibx, $txt); + $$txt .= $ibx->isrch->help_txt; $$txt .= <