unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/5] various minor annoyance fixups
@ 2022-08-20  8:01 Eric Wong
  2022-08-20  8:01 ` [PATCH 1/5] import: take advantage of some Perl 5.10.x features Eric Wong
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eric Wong @ 2022-08-20  8:01 UTC (permalink / raw)
  To: meta

Some things I noticed while reading the code, some things
I noticed while looking at WWW in w3m.  There were more cleanups
related to {base_url} and redundancies in WWW that I could
probably get rid of, but some had unintended side-effects :x
or required more refactoring/cleanups.

Eric Wong (5):
  import: take advantage of some Perl 5.10.x features
  imap: remove some intermediate arrays
  view: do not show pagination footer for small inboxes
  www: use absolute URLs for coderepo URLs
  www: mbox* drop unneeded {base_url} memoizations

 lib/PublicInbox/ExtSearch.pm |  4 +++-
 lib/PublicInbox/IMAP.pm      |  4 ++--
 lib/PublicInbox/Import.pm    | 23 ++++++++++-------------
 lib/PublicInbox/Inbox.pm     |  2 ++
 lib/PublicInbox/Mbox.pm      |  3 +--
 lib/PublicInbox/MboxGz.pm    |  3 +--
 lib/PublicInbox/View.pm      |  9 +++------
 lib/PublicInbox/WwwStream.pm | 16 ++++++++--------
 lib/PublicInbox/WwwText.pm   | 12 ++----------
 9 files changed, 32 insertions(+), 44 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] import: take advantage of some Perl 5.10.x features
  2022-08-20  8:01 [PATCH 0/5] various minor annoyance fixups Eric Wong
@ 2022-08-20  8:01 ` Eric Wong
  2022-08-20  8:01 ` [PATCH 2/5] imap: remove some intermediate arrays Eric Wong
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2022-08-20  8:01 UTC (permalink / raw)
  To: meta

We can save a few lines of code this way and reduce the
verbosity of some lines we keep.
---
 lib/PublicInbox/Import.pm | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 60ce7b66..aef49033 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # git fast-import-based ssoma-mda MDA replacement
@@ -103,7 +103,7 @@ sub _check_path ($$$$) {
 	return if $tip eq '';
 	print $w "ls $tip $path\n" or wfail;
 	local $/ = "\n";
-	defined(my $info = <$r>) or die "EOF from fast-import: $!";
+	my $info = <$r> // die "EOF from fast-import: $!";
 	$info =~ /\Amissing / ? undef : $info;
 }
 
@@ -111,22 +111,21 @@ sub _cat_blob ($$$) {
 	my ($r, $w, $oid) = @_;
 	print $w "cat-blob $oid\n" or wfail;
 	local $/ = "\n";
-	my $info = <$r>;
-	defined $info or die "EOF from fast-import / cat-blob: $!";
+	my $info = <$r> // die "EOF from fast-import / cat-blob: $!";
 	$info =~ /\A[a-f0-9]{40,} blob ([0-9]+)\n\z/ or return;
 	my $left = $1;
 	my $offset = 0;
 	my $buf = '';
 	my $n;
 	while ($left > 0) {
-		$n = read($r, $buf, $left, $offset);
-		defined($n) or die "read cat-blob failed: $!";
+		$n = read($r, $buf, $left, $offset) //
+			die "read cat-blob failed: $!";
 		$n == 0 and die 'fast-export (cat-blob) died';
 		$left -= $n;
 		$offset += $n;
 	}
-	$n = read($r, my $lf, 1);
-	defined($n) or die "read final byte of cat-blob failed: $!";
+	$n = read($r, my $lf, 1) //
+		die "read final byte of cat-blob failed: $!";
 	die "bad read on final byte: <$lf>" if $lf ne "\n";
 
 	# fixup some bugginess in old versions:
@@ -148,10 +147,8 @@ sub check_remove_v1 {
 	my $oid = $1;
 	my $msg = _cat_blob($r, $w, $oid) or die "BUG: cat-blob $1 failed";
 	my $cur = PublicInbox::Eml->new($msg);
-	my $cur_s = $cur->header('Subject');
-	$cur_s = '' unless defined $cur_s;
-	my $cur_m = $mime->header('Subject');
-	$cur_m = '' unless defined $cur_m;
+	my $cur_s = $cur->header('Subject') // '';
+	my $cur_m = $mime->header('Subject') // '';
 	if ($cur_s ne $cur_m || norm_body($cur) ne norm_body($mime)) {
 		return ('MISMATCH', $cur);
 	}
@@ -219,7 +216,7 @@ sub get_mark {
 	die "not active\n" unless $self->{in};
 	my ($r, $w) = $self->gfi_start;
 	print $w "get-mark $mark\n" or wfail;
-	defined(my $oid = <$r>) or die "get-mark failed, need git 2.6.0+\n";
+	my $oid = <$r> // die "get-mark failed, need git 2.6.0+\n";
 	chomp($oid);
 	$oid;
 }

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] imap: remove some intermediate arrays
  2022-08-20  8:01 [PATCH 0/5] various minor annoyance fixups Eric Wong
  2022-08-20  8:01 ` [PATCH 1/5] import: take advantage of some Perl 5.10.x features Eric Wong
@ 2022-08-20  8:01 ` Eric Wong
  2022-08-20  8:01 ` [PATCH 3/5] view: do not show pagination footer for small inboxes Eric Wong
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2022-08-20  8:01 UTC (permalink / raw)
  To: meta

We can assign arrays directly without `[]' creating an extra
immortal pad allocation.
---
 lib/PublicInbox/IMAP.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 0a65d87c..1f65aa65 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -1005,7 +1005,7 @@ sub fetch_compile ($) {
 	# stabilize partial order for consistency and ease-of-debugging:
 	if (scalar keys %partial) {
 		$need |= NEED_BLOB;
-		$r[2] = [ map { [ $_, @{$partial{$_}} ] } sort keys %partial ];
+		@{$r[2]} = map { [ $_, @{$partial{$_}} ] } sort keys %partial;
 	}
 
 	push @op, $OP_EML_NEW if ($need & (EML_HDR|EML_BDY));
@@ -1028,7 +1028,7 @@ sub fetch_compile ($) {
 
 	# r[1] = [ $key1, $cb1, $key2, $cb2, ... ]
 	use sort 'stable'; # makes output more consistent
-	$r[1] = [ map { ($_->[2], $_->[1]) } sort { $a->[0] <=> $b->[0] } @op ];
+	@{$r[1]} = map { ($_->[2], $_->[1]) } sort { $a->[0] <=> $b->[0] } @op;
 	@r;
 }
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] view: do not show pagination footer for small inboxes
  2022-08-20  8:01 [PATCH 0/5] various minor annoyance fixups Eric Wong
  2022-08-20  8:01 ` [PATCH 1/5] import: take advantage of some Perl 5.10.x features Eric Wong
  2022-08-20  8:01 ` [PATCH 2/5] imap: remove some intermediate arrays Eric Wong
@ 2022-08-20  8:01 ` Eric Wong
  2022-08-20  8:01 ` [PATCH 4/5] www: use absolute URLs for coderepo URLs Eric Wong
  2022-08-20  8:01 ` [PATCH 5/5] www: mbox* drop unneeded {base_url} memoizations Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2022-08-20  8:01 UTC (permalink / raw)
  To: meta

For new public inboxes with few messages, the dead pagination
footer is a worthless and confusing waste of space: "page: \n";
without `next' or `prev' links for users to follow.
---
 lib/PublicInbox/View.pm | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 26094082..c28505f1 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -1192,7 +1192,7 @@ sub pagination_footer ($$) {
 		$next = $next ? "$next | " : '             | ';
 		$prev .= qq[ | <a\nhref="$latest">latest</a>];
 	}
-	"<hr><pre>page: $next$prev</pre>";
+	($next || $prev) ? \"<hr><pre>page: $next$prev</pre>" : \'';
 }
 
 sub paginate_recent ($$) {
@@ -1243,11 +1243,8 @@ sub paginate_recent ($$) {
 sub index_topics {
 	my ($ctx) = @_;
 	my $msgs = paginate_recent($ctx, 200); # 200 is our window
-	if (@$msgs) {
-		walk_thread(thread_results($ctx, $msgs), $ctx, \&acc_topic);
-	}
-	html_oneshot($ctx, dump_topics($ctx), \pagination_footer($ctx, '.'));
-
+	walk_thread(thread_results($ctx, $msgs), $ctx, \&acc_topic) if @$msgs;
+	html_oneshot($ctx, dump_topics($ctx), pagination_footer($ctx, '.'));
 }
 
 sub thread_adj_level {

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] www: use absolute URLs for coderepo URLs
  2022-08-20  8:01 [PATCH 0/5] various minor annoyance fixups Eric Wong
                   ` (2 preceding siblings ...)
  2022-08-20  8:01 ` [PATCH 3/5] view: do not show pagination footer for small inboxes Eric Wong
@ 2022-08-20  8:01 ` Eric Wong
  2022-08-20  8:01 ` [PATCH 5/5] www: mbox* drop unneeded {base_url} memoizations Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2022-08-20  8:01 UTC (permalink / raw)
  To: meta

Showing "../../foo.git" looks awkward and isn't conducive to
users who want to "git clone" a URL.
---
 lib/PublicInbox/ExtSearch.pm |  4 +++-
 lib/PublicInbox/Inbox.pm     |  2 ++
 lib/PublicInbox/WwwStream.pm | 16 ++++++++--------
 lib/PublicInbox/WwwText.pm   | 12 ++----------
 4 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/lib/PublicInbox/ExtSearch.pm b/lib/PublicInbox/ExtSearch.pm
index 2460d74f..3eb864a2 100644
--- a/lib/PublicInbox/ExtSearch.pm
+++ b/lib/PublicInbox/ExtSearch.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # Read-only external (detached) index for cross inbox search.
@@ -117,6 +117,8 @@ sub search {
 	$_[0];
 }
 
+sub thing_type { 'external index' }
+
 no warnings 'once';
 *base_url = \&PublicInbox::Inbox::base_url;
 *smsg_eml = \&PublicInbox::Inbox::smsg_eml;
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 1f7f982d..acd7f338 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -431,4 +431,6 @@ sub mailboxid { # rfc 8474, 8620, 8621
 		sprintf('-%x', uidvalidity($self) // 0)
 }
 
+sub thing_type { 'public inbox' }
+
 1;
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index aee78170..0416db0b 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # HTML body stream for which yields getline+close methods for
@@ -86,17 +86,17 @@ sub coderepos ($) {
 	my $cr = $ctx->{ibx}->{coderepo} // return ();
 	my $cfg = $ctx->{www}->{pi_cfg};
 	my $upfx = ($ctx->{-upfx} // ''). '../';
-	my @ret;
+	my $pfx = $ctx->{base_url} //= $ctx->base_url;
+	my $up = $upfx =~ tr!/!/!;
+	$pfx =~ s!/[^/]+\z!/! for (1..$up);
+	my @ret = ('<a id=code>' .
+		'Code repositories for project(s) associated with this '.
+		$ctx->{ibx}->thing_type . "\n");
 	for my $cr_name (@$cr) {
-		$ret[0] //= <<EOF;
-<a id=code>Code repositories for project(s) associated with this inbox:
-EOF
 		my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl");
 		if ($urls) {
 			for (@$urls) {
-				# relative or absolute URL?, prefix relative
-				# "foo.git" with appropriate number of "../"
-				my $u = m!\A(?:[a-z\+]+:)?//! ? $_ : $upfx.$_;
+				my $u = m!\A(?:[a-z\+]+:)?//! ? $_ : $pfx.$_;
 				$u = ascii_html(prurl($ctx->{env}, $u));
 				$ret[0] .= qq(\n\t<a\nhref="$u">$u</a>);
 			}
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index 581a19f3..c6957e81 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -246,20 +246,12 @@ sub coderepos_raw ($$) {
 	my ($ctx, $top_url) = @_;
 	my $cr = $ctx->{ibx}->{coderepo} // return ();
 	my $cfg = $ctx->{www}->{pi_cfg};
-	my @ret;
+	my @ret = ('Code repositories for project(s) associated with this '.
+		$ctx->{ibx}->thing_type . "\n");
 	for my $cr_name (@$cr) {
-		$ret[0] //= do {
-			my $thing = $ctx->{ibx}->can('cloneurl') ?
-				'public inbox' : 'external index';
-			<<EOF;
-Code repositories for project(s) associated with this $thing
-EOF
-		};
 		my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl");
 		if ($urls) {
 			for (@$urls) {
-				# relative or absolute URL?, prefix relative
-				# "foo.git" with appropriate number of "../"
 				my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ :
 					$top_url.$_;
 				$ret[0] .= "\n\t" . prurl($ctx->{env}, $u);

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] www: mbox* drop unneeded {base_url} memoizations
  2022-08-20  8:01 [PATCH 0/5] various minor annoyance fixups Eric Wong
                   ` (3 preceding siblings ...)
  2022-08-20  8:01 ` [PATCH 4/5] www: use absolute URLs for coderepo URLs Eric Wong
@ 2022-08-20  8:01 ` Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2022-08-20  8:01 UTC (permalink / raw)
  To: meta

That field is not needed since List-* and Archived-At headers
are no longer appended as of commit:
1bf653ad139bf7bb (nntp+www: drop List-* and Archived-At headers, 2020-12-10)
---
 lib/PublicInbox/Mbox.pm   | 3 +--
 lib/PublicInbox/MboxGz.pm | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index e65f38f0..2ef8ff2b 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # Streaming interface for mboxrd HTTP responses
@@ -82,7 +82,6 @@ sub no_over_raw ($) {
 # /$INBOX/$MESSAGE_ID/raw
 sub emit_raw {
 	my ($ctx) = @_;
-	$ctx->{base_url} = $ctx->{ibx}->base_url($ctx->{env});
 	my $over = $ctx->{ibx}->over or return no_over_raw($ctx);
 	my ($id, $prev);
 	my $mip = $ctx->{next_arg} = [ $ctx->{mid}, \$id, \$prev ];
diff --git a/lib/PublicInbox/MboxGz.pm b/lib/PublicInbox/MboxGz.pm
index 3ed33867..56f5adcf 100644
--- a/lib/PublicInbox/MboxGz.pm
+++ b/lib/PublicInbox/MboxGz.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 package PublicInbox::MboxGz;
 use strict;
@@ -22,7 +22,6 @@ sub async_next ($) {
 sub mbox_gz {
 	my ($self, $cb, $fn) = @_;
 	$self->{cb} = $cb;
-	$self->{base_url} = $self->{ibx}->base_url($self->{env});
 	$self->{gz} = PublicInbox::GzipFilter::gzip_or_die();
 	$fn = to_filename($fn // '') // 'no-subject';
 	# http://www.iana.org/assignments/media-types/application/gzip

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-08-20  8:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-20  8:01 [PATCH 0/5] various minor annoyance fixups Eric Wong
2022-08-20  8:01 ` [PATCH 1/5] import: take advantage of some Perl 5.10.x features Eric Wong
2022-08-20  8:01 ` [PATCH 2/5] imap: remove some intermediate arrays Eric Wong
2022-08-20  8:01 ` [PATCH 3/5] view: do not show pagination footer for small inboxes Eric Wong
2022-08-20  8:01 ` [PATCH 4/5] www: use absolute URLs for coderepo URLs Eric Wong
2022-08-20  8:01 ` [PATCH 5/5] www: mbox* drop unneeded {base_url} memoizations Eric Wong

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).