unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 5/5] lei: sort MH inputs sequentially by default
Date: Wed, 31 Jan 2024 10:20:20 +0000	[thread overview]
Message-ID: <20240131102021.1257902-6-e@80x24.org> (raw)
In-Reply-To: <20240131102021.1257902-1-e@80x24.org>

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 |  2 +-
 lib/PublicInbox/MHreader.pm |  3 ++-
 t/mh_reader.t               | 14 ++++++++++----
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm
index 947a7a79..d003d983 100644
--- a/lib/PublicInbox/LeiInput.pm
+++ b/lib/PublicInbox/LeiInput.pm
@@ -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});
diff --git a/lib/PublicInbox/MHreader.pm b/lib/PublicInbox/MHreader.pm
index 033aa740..3e7bbd5c 100644
--- a/lib/PublicInbox/MHreader.pm
+++ b/lib/PublicInbox/MHreader.pm
@@ -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:
diff --git a/t/mh_reader.t b/t/mh_reader.t
index 711fc8aa..c81df32e 100644
--- a/t/mh_reader.t
+++ b/t/mh_reader.t
@@ -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;

      parent reply	other threads:[~2024-01-31 10:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31 10:20 [PATCH 0/5] more MH-related updates Eric Wong
2024-01-31 10:20 ` [PATCH 1/5] lei convert: explicitly allow --sort for inputs Eric Wong
2024-01-31 10:20 ` [PATCH 2/5] import: drop redundant `use' statement Eric Wong
2024-01-31 10:20 ` [PATCH 3/5] scripts/slrnspool2maildir: use MHreader and LeiToMail Eric Wong
2024-01-31 10:20 ` [PATCH 4/5] scripts/import_*: update usage to include lei tips Eric Wong
2024-01-31 10:20 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240131102021.1257902-6-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).