unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/6] lei config: send `git config' errors to pager
Date: Sun, 24 Sep 2023 05:42:12 +0000	[thread overview]
Message-ID: <20230924054214.3539091-5-e@80x24.org> (raw)
In-Reply-To: <20230924054214.3539091-1-e@80x24.org>

Our previous use of lei->cfg_dump was wrong as the extra arg was
never supported.  Instead, we need to capture the output of
`git config' and send it to the pager if ->cfg_dump fails.  We'll
also add a note to the user to quit the pager to continue.
---
 lib/PublicInbox/LEI.pm       |  2 +-
 lib/PublicInbox/LeiConfig.pm | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index a6d92eec..488006e0 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -1098,7 +1098,7 @@ sub pgr_err {
 	my ($self, @msg) = @_;
 	return warn(@msg) unless $self->{sock} && -t $self->{2};
 	start_pager($self, { LESS => 'RX' }); # no 'F' so we prompt
-	print { $self->{2} } @msg;
+	say { $self->{2} } @msg, '# -quit pager to continue-';
 	$self->{2}->autoflush(1);
 	stop_pager($self);
 	send($self->{sock}, 'wait', 0); # wait for user to quit pager
diff --git a/lib/PublicInbox/LeiConfig.pm b/lib/PublicInbox/LeiConfig.pm
index 23be9aaf..fd4b0eca 100644
--- a/lib/PublicInbox/LeiConfig.pm
+++ b/lib/PublicInbox/LeiConfig.pm
@@ -4,6 +4,8 @@ package PublicInbox::LeiConfig;
 use strict;
 use v5.10.1;
 use PublicInbox::PktOp;
+use Fcntl qw(SEEK_SET);
+use autodie qw(open seek);
 
 sub cfg_do_edit ($;$) {
 	my ($self, $reason) = @_;
@@ -22,8 +24,14 @@ sub cfg_do_edit ($;$) {
 sub cfg_edit_done { # PktOp
 	my ($self) = @_;
 	eval {
-		my $cfg = $self->{lei}->cfg_dump($self->{-f}, $self->{lei}->{2})
-			// return cfg_do_edit($self, "\n");
+		open my $fh, '+>', undef or die "open($!)";
+		my $cfg = do {
+			local $self->{lei}->{2} = $fh;
+			$self->{lei}->cfg_dump($self->{-f});
+		} or do {
+			seek($fh, 0, SEEK_SET);
+			return cfg_do_edit($self, do { local $/; <$fh> });
+		};
 		$self->cfg_verify($cfg) if $self->can('cfg_verify');
 	};
 	$self->{lei}->fail($@) if $@;

  parent reply	other threads:[~2023-09-24  5:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-24  5:42 [PATCH 0/6] lei config fixes and improvements Eric Wong
2023-09-24  5:42 ` [PATCH 1/6] lei: check git-config(1) failures Eric Wong
2023-09-24  5:42 ` [PATCH 2/6] lei view_text: used tied ProcessPipe for `git config' Eric Wong
2023-09-24  5:42 ` [PATCH 3/6] config: handle key-only entries as booleans Eric Wong
2023-09-24  5:42 ` Eric Wong [this message]
2023-09-24  5:42 ` [PATCH 5/6] lei: fix `-c NAME=VALUE' config support Eric Wong
2023-09-24  5:42 ` [PATCH 6/6] config: drop scalar ref support from internal API Eric Wong
2023-09-24  9:50   ` [SQUASH 7/6] t/config: fix missing coderepo.<PROJECT>.dir entry Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230924054214.3539091-5-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).