]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei: sort MH inputs sequentially by default
authorEric Wong <e@80x24.org>
Wed, 31 Jan 2024 10:20:20 +0000 (10:20 +0000)
committerEric Wong <e@80x24.org>
Thu, 1 Feb 2024 21:00:17 +0000 (21:00 +0000)
MH sequence numbers can be analogous to IMAP UIDs and NNTP
article numbers (or more like IMAP MSNs with clients which
pack).  In any case, sort then numerically by default to avoid
surprising users who treat NNTP spools and mlmmj archives as MH
folders.  This gives more coherent git history and resulting
NNTP/IMAP numbering when round-tripping MH -> v2 -> (NNTP|IMAP) -> MH

lib/PublicInbox/LeiInput.pm
lib/PublicInbox/MHreader.pm
t/mh_reader.t

index 947a7a79692b31648f370bc51e0ee85414ac12fa..d003d983614e6ac130708c8612899b5ddc2e3087 100644 (file)
@@ -242,7 +242,7 @@ sub input_path_url {
                }
        } elsif (-d _ && $ifmt eq 'mh') {
                my $mhr = PublicInbox::MHreader->new($input.'/', $lei->{3});
-               $mhr->{sort} = $lei->{opt}->{sort};
+               $mhr->{sort} = $lei->{opt}->{sort} // [ 'sequence'];
                $mhr->mh_each_eml($self->can('input_mh_cb'), $self, @args);
        } elsif (-d _ && $ifmt =~ /\A(?:v1|v2)\z/) {
                my $ibx = PublicInbox::Inbox->new({inboxdir => $input});
index 033aa7404c8438d59816faab174499bee81b00d0..3e7bbd5c0202f2511c8ad5151a362d9ed8d0d590 100644 (file)
@@ -54,7 +54,8 @@ sub mh_each_file {
        opendir(my $dh, my $dir = $self->{dir});
        my $restore = PublicInbox::OnDestroy->new($$, \&chdir, $self->{cwdfh});
        chdir($dh);
-       if (defined(my $sort = $self->{sort})) {
+       my $sort = $self->{sort};
+       if (defined $sort && "@$sort" ne 'none') {
                my @sort = map {
                        my @tmp = $_ eq '' ? ('sequence') : split(/[, ]/);
                        # sorting by name alphabetically makes no sense for MH:
index 711fc8aacbe6dfb9a008b29288ca04167b943a9f..c81df32e369aa396cf74f15d0f111e53bf571082 100644 (file)
@@ -7,6 +7,7 @@ use PublicInbox::IO qw(write_file);
 use PublicInbox::Lock;
 use PublicInbox::OnDestroy;
 use PublicInbox::Eml;
+use File::Path qw(remove_tree);
 use autodie;
 opendir my $cwdfh, '.';
 
@@ -103,12 +104,17 @@ test_lei(sub {
        like $lei_out, qr/^Subject: msg 4\nStatus: RO\n\n\n/ms,
                "message retrieved after `lei index'";
 
+       lei_ok qw(convert -s none -f text), "mh:$for_sort", \'--sort=none';
+
        # ensure sort works for _input_ when output disallows sort
        my $v2out = "$ENV{HOME}/v2-out";
-       lei_ok qw(convert -s sequence), "mh:$for_sort", '-o', "v2:$v2out";
-       my $git = PublicInbox::Git->new("$v2out/git/0.git");
-       chomp(my @l = $git->qx(qw(log --pretty=oneline --format=%s)));
-       is_xdeeply \@l, [1, 22, 333], 'sequence order preserved for v2';
+       for my $sort (['--sort=sequence'], []) { # sequence is the default
+               lei_ok qw(convert), @$sort, "mh:$for_sort", '-o', "v2:$v2out";
+               my $g = PublicInbox::Git->new("$v2out/git/0.git");
+               chomp(my @l = $g->qx(qw(log --pretty=oneline --format=%s)));
+               is_xdeeply \@l, [1, 22, 333], 'sequence order preserved for v2';
+               File::Path::remove_tree $v2out;
+       }
 });
 
 done_testing;