From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B45431FA19 for ; Sat, 1 May 2021 06:21:17 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/5] lei edit-search: support relocating lei.q.output Date: Sat, 1 May 2021 06:21:17 +0000 Message-Id: <20210501062117.21617-6-e@80x24.org> In-Reply-To: <20210501062117.21617-1-e@80x24.org> References: <20210501062117.21617-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: The contents of the old lei.q.output will not be removed, but will be converted into the new one. --- lib/PublicInbox/LeiConvert.pm | 5 ++- lib/PublicInbox/LeiEditSearch.pm | 15 +++++++-- lib/PublicInbox/LeiSavedSearch.pm | 51 +++++++++++++++++++++++++++++++ script/lei | 7 +++++ 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm index cefcaf65..5b27ec2d 100644 --- a/lib/PublicInbox/LeiConvert.pm +++ b/lib/PublicInbox/LeiConvert.pm @@ -37,8 +37,11 @@ sub process_inputs { # via wq_do my ($self) = @_; local $PublicInbox::DS::in_loop = 0; # force synchronous dwaitpid $self->SUPER::process_inputs; - delete $self->{lei}->{1}; + my $lei = $self->{lei}; + delete $lei->{1}; delete $self->{wcb}; # commit + my $nr = delete($lei->{-nr_write}) // 0; + $lei->err("# converted $nr messages") if $lei->{opt}->{verbose}; } sub lei_convert { # the main "lei convert" method diff --git a/lib/PublicInbox/LeiEditSearch.pm b/lib/PublicInbox/LeiEditSearch.pm index fb36fdcd..30ac65bd 100644 --- a/lib/PublicInbox/LeiEditSearch.pm +++ b/lib/PublicInbox/LeiEditSearch.pm @@ -13,10 +13,19 @@ sub lei_edit_search { my $lss = PublicInbox::LeiSavedSearch->up($lei, $out) or return; my @cmd = (qw(git config --edit -f), $lss->{'-f'}); $lei->qerr("# spawning @cmd"); + $lss->edit_begin($lei); if ($lei->{oneshot}) { - exec(@cmd) or die "exec @cmd: $!\n"; - } else { - $lei->send_exec_cmd([], \@cmd, {}); + require PublicInbox::Spawn; + waitpid(PublicInbox::Spawn::spawn(\@cmd), 0); + # non-fatal, editor could fail after successful write + $lei->child_error($?) if $?; + $lss->edit_done($lei); + } else { # run in script/lei foreground + require PublicInbox::PktOp; + my ($op_c, $op_p) = PublicInbox::PktOp->pair; + # $op_p will EOF when $EDITOR is done + $op_c->{ops} = { '' => [$lss->can('edit_done'), $lss, $lei] }; + $lei->send_exec_cmd([ @$lei{qw(0 1 2)}, $op_p ], \@cmd, {}); } } diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm index 79125214..8177c98e 100644 --- a/lib/PublicInbox/LeiSavedSearch.pm +++ b/lib/PublicInbox/LeiSavedSearch.pm @@ -259,6 +259,57 @@ sub output2lssdir { undef; } +sub edit_begin { + my ($self, $lei) = @_; + if (ref($self->{-cfg}->{'lei.q.output'})) { + delete $self->{-cfg}->{'lei.q.output'}; # invalid + $lei->err(<{-f} has multiple values of lei.q.output +please remove redundant ones +EOM + } + $lei->{-lss_for_edit} = $self; +} + +sub edit_done { + my ($self, $lei) = @_; + my $cfg = PublicInbox::Config->git_config_dump($self->{'-f'}); + my $new_out = $cfg->{'lei.q.output'} // ''; + return $lei->fail(<{-f} has multiple values of lei.q.output +please edit again +EOM + return $lei->fail(<{-f} needs lei.q.output +please edit again +EOM + my $old_out = $self->{-cfg}->{'lei.q.output'} // ''; + return if $old_out eq $new_out; + my $old_path = $old_out; + my $new_path = $new_out; + s!$LOCAL_PFX!! for ($old_path, $new_path); + my $dir_old = lss_dir_for($lei, \$old_path, 1); + my $dir_new = lss_dir_for($lei, \$new_path); + return if $dir_new eq $dir_old; # no change, likely + return $lei->fail(<puts("lei.q.output changed from $old_sq to $new_sq"); + $lei->qerr("# lei convert $old_sq -o $new_sq"); + my $v = !$lei->{opt}->{quiet}; + $lei->{opt} = { output => $new_out, verbose => $v }; + require PublicInbox::LeiConvert; + PublicInbox::LeiConvert::lei_convert($lei, $old_out); + + $lei->fail(<