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 $@;

Reply via email to