1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # The "lei mail-diff" sub-command, diffs input contents against
5 # the first message of input
6 package PublicInbox::LeiMailDiff;
8 use parent qw(PublicInbox::IPC PublicInbox::LeiInput PublicInbox::MailDiff);
9 use PublicInbox::Spawn qw(spawn which);
11 require PublicInbox::LeiRediff;
14 my ($self, $eml) = @_;
15 my $dir = "$self->{tmp}/N".(++$self->{nr});
16 $self->dump_eml($dir, $eml);
17 my $cmd = [ qw(git diff --no-index) ];
18 my $lei = $self->{lei};
19 PublicInbox::LeiRediff::_lei_diff_prepare($lei, $cmd);
20 push @$cmd, qw(-- a), "N$self->{nr}";
21 my $rdr = { -C => "$self->{tmp}" };
22 @$rdr{1, 2} = @$lei{1, 2};
23 my $pid = spawn($cmd, $lei->{env}, $rdr);
25 $lei->child_error($?) if $?; # for git diff --exit-code
26 File::Path::remove_tree($self->{curdir});
29 sub input_eml_cb { # used by PublicInbox::LeiInput::input_fh
30 my ($self, $eml) = @_;
31 $self->{tmp} ? diff_a($self, $eml) : $self->prep_a($eml);
35 my ($lei, @argv) = @_;
36 my $self = bless {}, __PACKAGE__;
37 $self->prepare_inputs($lei, \@argv) or return;
38 my $isatty = -t $lei->{1};
39 $lei->{opt}->{color} //= $isatty;
40 $lei->start_pager if $isatty;
41 $lei->{-err_type} = 'non-fatal';
42 $self->{-raw_hdr} = $lei->{opt}->{'raw-header'};
43 $lei->wq1_start($self);
47 *net_merge_all_done = \&PublicInbox::LeiInput::input_only_net_merge_all_done;