X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FLeiEditSearch.pm;h=bcf7c10517c95c7718efb5359ffced25125a57a6;hb=23af251dd607c4e75ab1e68063f2c885c48cc035;hp=30ac65bdc18c7d402abb410f203d27cddc25df15;hpb=6dbc443f8acfb262ca1ab263b60ecb801c00aac2;p=public-inbox.git diff --git a/lib/PublicInbox/LeiEditSearch.pm b/lib/PublicInbox/LeiEditSearch.pm index 30ac65bd..bcf7c105 100644 --- a/lib/PublicInbox/LeiEditSearch.pm +++ b/lib/PublicInbox/LeiEditSearch.pm @@ -7,26 +7,68 @@ use strict; use v5.10.1; use PublicInbox::LeiSavedSearch; use PublicInbox::LeiUp; +use parent qw(PublicInbox::LeiConfig); + +sub cfg_edit_begin { + my ($self) = @_; + if (ref($self->{lss}->{-cfg}->{'lei.q.output'})) { + delete $self->{lss}->{-cfg}->{'lei.q.output'}; # invalid + $self->{lei}->pgr_err(<{lss}->{-f} has multiple values of lei.q.output +please remove redundant ones +EOM + } +} + +sub cfg_verify { + my ($self, $cfg) = @_; + my $new_out = $cfg->{'lei.q.output'} // ''; + return $self->cfg_do_edit(<{-f} has multiple values of lei.q.output +EOM + return $self->cfg_do_edit(<{-f} needs lei.q.output +EOM + my $lss = $self->{lss}; + my $old_out = $lss->{-cfg}->{'lei.q.output'} // return; + return if $old_out eq $new_out; + my $lei = $self->{lei}; + my $old_path = $old_out; + my $new_path = $new_out; + s!$PublicInbox::LeiSavedSearch::LOCAL_PFX!! for ($old_path, $new_path); + my $dir_old = $lss->can('lss_dir_for')->($lei, \$old_path, 1); + my $dir_new = $lss->can('lss_dir_for')->($lei, \$new_path); + return if $dir_new eq $dir_old; + + ($old_out =~ m!\Av2:!i || $new_out =~ m!\Av2:!) and + return $self->cfg_do_edit(<cfg_do_edit(<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(<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}) { - 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, {}); - } + my $f = $lss->{-f}; + my $self = bless { lei => $lei, lss => $lss, -f => $f }, __PACKAGE__; + $self->cfg_do_edit; } *_complete_edit_search = \&PublicInbox::LeiUp::_complete_up;