user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] lei_saved_search: avoid git-config
@ 2021-04-17 20:19 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-04-17 20:19 UTC (permalink / raw)
  To: meta

Repeated vfork+execv costing us around 20ms on t/lei-q-save.t,
so just learn to quote git-config values and write directly to
the config file.
---
 lib/PublicInbox/LeiSavedSearch.pm | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm
index e44779ee..f40fe76b 100644
--- a/lib/PublicInbox/LeiSavedSearch.pm
+++ b/lib/PublicInbox/LeiSavedSearch.pm
@@ -15,6 +15,14 @@ use Digest::SHA qw(sha256_hex);
 
 *squote_maybe = \&PublicInbox::Config::squote_maybe;
 
+# move this to PublicInbox::Config if other things use it:
+my %cquote = ("\n" => '\\n', "\t" => '\\t', "\b" => '\\b');
+sub cquote_val ($) { # cf. git-config(1)
+	my ($val) = @_;
+	$val =~ s/([\n\t\b])/$cquote{$1}/g;
+	$val;
+}
+
 sub lss_dir_for ($$) {
 	my ($lei, $dstref) = @_;
 	my @n;
@@ -54,29 +62,32 @@ sub new {
 		my $f = $self->{'-f'} = "$dir/lei.saved-search";
 		open my $fh, '>', $f or return $lei->fail("open $f: $!");
 		my $sq_dst = squote_maybe($dst);
-		print $fh <<EOM or return $lei->fail("print $f: $!");
-; to refresh with new results, run: lei up $sq_dst
-EOM
-		close $fh or return $lei->fail("close $f: $!");
 		my $q = $lei->{mset_opt}->{q_raw} // die 'BUG: {q_raw} missing';
 		if (ref $q) {
-			cfg_set($self, '--add', 'lei.q', $_) for @$q;
+			$q = join("\n", map { "\tq = ".cquote_val($_) } @$q);
 		} else {
-			cfg_set($self, 'lei.q', $q);
+			$q = "\tq = ".cquote_val($q);
 		}
 		$dst = "$lei->{ovv}->{fmt}:$dst" if $dst !~ m!\Aimaps?://!i;
-		cfg_set($self, 'lei.q.output', $dst);
+		print $fh <<EOM;
+; to refresh with new results, run: lei up $sq_dst
+[lei]
+$q
+[lei "q"]
+	output = $dst
+EOM
 		for my $k (qw(only include exclude)) {
 			my $ary = $lei->{opt}->{$k} // next;
 			for my $x (@$ary) {
-				cfg_set($self, '--add', "lei.q.$k", $x);
+				print $fh "\t$k = ".cquote_val($x)."\n";
 			}
 		}
 		for my $k (qw(external local remote import-remote
 				import-before threads)) {
 			my $val = $lei->{opt}->{$k} // next;
-			cfg_set($self, "lei.q.$k", $val);
+			print $fh "\t$k = ".cquote_val($val)."\n";
 		}
+		close($fh) or return $lei->fail("close $f: $!");
 	}
 	bless $self->{-cfg}, 'PublicInbox::Config';
 	$self->{lock_path} = "$self->{-f}.flock";
@@ -86,7 +97,7 @@ EOM
 
 sub description { $_[0]->{qstr} } # for WWW
 
-sub cfg_set {
+sub cfg_set { # called by LeiXSearch
 	my ($self, @args) = @_;
 	my $lk = $self->lock_for_scope; # git-config doesn't wait
 	run_die([qw(git config -f), $self->{'-f'}, @args]);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-17 20:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-17 20:19 [PATCH] lei_saved_search: avoid git-config Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git