user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 1/6] lei: check git-config(1) failures
  2023-09-24  5:42  6% [PATCH 0/6] lei config fixes and improvements Eric Wong
@ 2023-09-24  5:42  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-09-24  5:42 UTC (permalink / raw)
  To: meta

2020-2021 were bad times and I somehow got deluded into
believing git-config(1) would always succeed :x
---
 lib/PublicInbox/LEI.pm               | 9 ++++++---
 lib/PublicInbox/LeiAddWatch.pm       | 7 ++++---
 lib/PublicInbox/LeiForgetExternal.pm | 3 +--
 lib/PublicInbox/LeiInit.pm           | 4 ++--
 lib/PublicInbox/LeiRmWatch.pm        | 2 +-
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 368f9357..a6d92eec 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -776,9 +776,8 @@ EOM
 		/\A([^=\.]+\.[^=]+)(?:=(.*))?\z/ or return fail($self, <<EOM);
 `-c $_' is not of the form -c <name>=<value>'
 EOM
-		my $name = $1;
-		my $value = $2 // 1;
-		_config($self, '--add', $name, $value);
+		my ($name, $value) = ($1, $2 // 1);
+		_config($self, '--add', $name, $value) or return;
 		if (defined(my $v = $tmp->{$name})) {
 			if (ref($v) eq 'ARRAY') {
 				push @$v, $value;
@@ -894,13 +893,17 @@ sub _lei_store ($;$) {
 	};
 }
 
+# returns true on success, undef
+# argv[0] eq `+e' means errors do not ->fail # (like `sh +e')
 sub _config {
 	my ($self, @argv) = @_;
+	my $err_ok = ($argv[0] // '') eq '+e' ? shift(@argv) : undef;
 	my %env = (%{$self->{env}}, GIT_CONFIG => undef);
 	my $cfg = _lei_cfg($self, 1);
 	my $cmd = [ qw(git config -f), $cfg->{'-f'}, @argv ];
 	my %rdr = map { $_ => $self->{$_} } (0..2);
 	waitpid(spawn($cmd, \%env, \%rdr), 0);
+	$? == 0 ? 1 : ($err_ok ? undef : fail($self, $?));
 }
 
 sub lei_daemon_pid { puts shift, $$ }
diff --git a/lib/PublicInbox/LeiAddWatch.pm b/lib/PublicInbox/LeiAddWatch.pm
index 97e7a342..f61e2de4 100644
--- a/lib/PublicInbox/LeiAddWatch.pm
+++ b/lib/PublicInbox/LeiAddWatch.pm
@@ -26,13 +26,14 @@ sub lei_add_watch {
 	for my $w (@{$self->{inputs}}) {
 		# clobber existing, allow multiple
 		if (defined($vmd0)) {
-			$lei->_config("watch.$w.vmd", '--replace-all', $vmd0);
+			$lei->_config("watch.$w.vmd", '--replace-all', $vmd0)
+				or return;
 			for my $v (@vmd) {
-				$lei->_config("watch.$w.vmd", $v);
+				$lei->_config("watch.$w.vmd", $v) or return;
 			}
 		}
 		next if defined $cfg->{"watch.$w.state"};
-		$lei->_config("watch.$w.state", $state);
+		$lei->_config("watch.$w.state", $state) or return;
 	}
 	$lei->_lei_store(1); # create
 	$lei->lms(1)->lms_write_prepare->add_folders(@{$self->{inputs}});
diff --git a/lib/PublicInbox/LeiForgetExternal.pm b/lib/PublicInbox/LeiForgetExternal.pm
index 39bfc60b..c8d1df38 100644
--- a/lib/PublicInbox/LeiForgetExternal.pm
+++ b/lib/PublicInbox/LeiForgetExternal.pm
@@ -16,8 +16,7 @@ sub lei_forget_external {
 			next if $seen{$l}++;
 			my $key = "external.$l.boost";
 			delete($cfg->{$key});
-			$lei->_config('--unset', $key);
-			if ($? == 0) {
+			if ($lei->_config('+e', '--unset', $key)) {
 				$lei->qerr("# $l forgotten ");
 			} elsif (($? >> 8) == 5) {
 				warn("# $l not found\n");
diff --git a/lib/PublicInbox/LeiInit.pm b/lib/PublicInbox/LeiInit.pm
index 27ce8169..94897e61 100644
--- a/lib/PublicInbox/LeiInit.pm
+++ b/lib/PublicInbox/LeiInit.pm
@@ -23,7 +23,7 @@ sub lei_init {
 
 		# some folks like symlinks and bind mounts :P
 		if (@dir && "@cur[1,0]" eq "@dir[1,0]") {
-			$self->_config('leistore.dir', $dir);
+			$self->_config('leistore.dir', $dir) or return;
 			$self->_lei_store(1)->done;
 			return $self->qerr("$exists (as $cur)");
 		}
@@ -31,7 +31,7 @@ sub lei_init {
 E: leistore.dir=$cur already initialized and it is not $dir
 
 	}
-	$self->_config('leistore.dir', $dir);
+	$self->_config('leistore.dir', $dir) or return;
 	$self->_lei_store(1)->done;
 	$exists //= "# leistore.dir=$dir newly initialized";
 	$self->qerr($exists);
diff --git a/lib/PublicInbox/LeiRmWatch.pm b/lib/PublicInbox/LeiRmWatch.pm
index c0f336f0..19bee3ab 100644
--- a/lib/PublicInbox/LeiRmWatch.pm
+++ b/lib/PublicInbox/LeiRmWatch.pm
@@ -14,7 +14,7 @@ sub lei_rm_watch {
 	my $self = bless { missing_ok => 1 }, __PACKAGE__;
 	$self->prepare_inputs($lei, \@argv) or return;
 	for my $w (@{$self->{inputs}}) {
-		$lei->_config('--remove-section', "watch.$w");
+		$lei->_config('--remove-section', "watch.$w") or return;
 	}
 	delete $lei->{cfg}; # force reload
 	$lei->refresh_watches;

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/6] lei config fixes and improvements
@ 2023-09-24  5:42  6% Eric Wong
  2023-09-24  5:42  7% ` [PATCH 1/6] lei: check git-config(1) failures Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-09-24  5:42 UTC (permalink / raw)
  To: meta

Fixing `-c NAME=VALUE' was something I noticed working on
improving *BSD support the other week.  Everything else
here was noticed while fixing -c.  And 6/6 is because I'm
annoyed at seeing test-only code in Config.pm

Eric Wong (6):
  lei: check git-config(1) failures
  lei view_text: used tied ProcessPipe for `git config'
  config: handle key-only entries as booleans
  lei config: send `git config' errors to pager
  lei: fix `-c NAME=VALUE' config support
  config: drop scalar ref support from internal API

 lib/PublicInbox/Config.pm            |  78 ++++++++++------
 lib/PublicInbox/LEI.pm               | 102 +++++++++++----------
 lib/PublicInbox/LeiAddWatch.pm       |   7 +-
 lib/PublicInbox/LeiConfig.pm         |  35 +++++---
 lib/PublicInbox/LeiForgetExternal.pm |   3 +-
 lib/PublicInbox/LeiInit.pm           |   4 +-
 lib/PublicInbox/LeiMirror.pm         |   5 +-
 lib/PublicInbox/LeiRmWatch.pm        |   2 +-
 lib/PublicInbox/LeiViewText.pm       |   9 +-
 lib/PublicInbox/TestCommon.pm        |  20 +++--
 t/config.t                           | 128 +++++++++++++++------------
 t/config_limiter.t                   |  31 +++----
 t/inbox_idle.t                       |  15 ++--
 t/lei.t                              |  17 +++-
 t/psgi_bad_mids.t                    |  18 ++--
 t/psgi_mount.t                       |  14 ++-
 t/psgi_multipart_not.t               |  16 ++--
 t/psgi_scan_all.t                    |  18 ++--
 t/psgi_search.t                      |  12 ++-
 t/psgi_text.t                        |  21 ++---
 t/watch_filter_rubylang.t            |  30 +++----
 t/watch_imap.t                       |  20 +++--
 t/watch_maildir.t                    |  24 ++---
 t/watch_maildir_v2.t                 |  44 ++++-----
 t/watch_multiple_headers.t           |  21 +++--
 25 files changed, 381 insertions(+), 313 deletions(-)


^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-09-24  5:42  6% [PATCH 0/6] lei config fixes and improvements Eric Wong
2023-09-24  5:42  7% ` [PATCH 1/6] lei: check git-config(1) failures Eric Wong

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).