From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C9F321F601 for ; Sat, 10 Sep 2022 20:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1662840624; bh=pAwg3JVkGq2QnZXCgZlInz49TqzLZ6O2lvWpsepHWgw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xGX50Rp3XXre2IjWFB9VZBOrBlV//lMK5J8TwZTeXH7a3y1y/Cnsug33p7SCWx8ut uIi1s9mUCN2Kc1p8scXJzhYP2mb55SHO8lNeQ7gu4NEmr5yGJrmt7b8wA3oUjMvZGp gpvD6uxqGFdh0JFE5977l4A2fKOPcjaDYwA8Dmq0= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/2] view: fix solver links with multiple messages Date: Sat, 10 Sep 2022 20:10:23 +0000 Message-Id: <20220910201024.9651-2-e@80x24.org> In-Reply-To: <20220910201024.9651-1-e@80x24.org> References: <20220910201024.9651-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: For redundant messages sharing Message-IDs, the link to solver (/$INBOX/$OID/s/) was going up too many levels for /$INBOX/$MSGID/ when there were multiple messages sharing the same $MSGID. Unfortunately, redundant messages are common with /all/ due to signature trailers. So dynamically assigning {-spfx} is tricky and error prone from counting `/'. So simplify the code a bit by setting {-spfx} once per HTTP request, instead of every single message. --- lib/PublicInbox/Feed.pm | 1 + lib/PublicInbox/View.pm | 20 ++------------------ lib/PublicInbox/WwwAtomStream.pm | 1 + 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index affe0fb6..de1e7dfe 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -70,6 +70,7 @@ sub new_html { } $ctx->{-html_tip} = '
';
 	$ctx->{-upfx} = '';
+	$ctx->{-spfx} = '' if $ctx->{ibx}->{coderepo};
 	$ctx->{-hr} = 1;
 	PublicInbox::WwwStream::aresponse($ctx, \&new_html_i);
 }
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 0753c06e..01c086bf 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -80,6 +80,7 @@ sub msg_page {
 	# allow user to easily browse the range around this message if
 	# they have ->over
 	$ctx->{-t_max} = $smsg->{ts};
+	$ctx->{-spfx} = '../' if $ibx->{coderepo};
 	PublicInbox::WwwStream::aresponse($ctx, \&msg_page_i);
 }
 
@@ -441,6 +442,7 @@ sub thread_html {
 	my $ibx = $ctx->{ibx};
 	my ($nr, $msgs) = $ibx->over->get_thread($mid);
 	return missing_thread($ctx) if $nr == 0;
+	$ctx->{-spfx} = '../../' if $ibx->{coderepo};
 
 	# link $INBOX_DIR/description text to "index_topics" view around
 	# the newest message in this thread
@@ -584,24 +586,6 @@ sub add_text_body { # callback for each_part
 		$ctx->{-anchors} = {} if $s =~ /^diff --git /sm;
 		$diff = 1;
 		delete $ctx->{-long_path};
-		my $spfx;
-		# absolute URL (Atom feeds)
-		if ($ibx->{coderepo}) {
-			if (index($upfx, '//') >= 0) {
-				$spfx = $upfx;
-				$spfx =~ s!/([^/]*)/\z!/!;
-			} else {
-				my $n_slash = $upfx =~ tr!/!/!;
-				if ($n_slash == 0) {
-					$spfx = '../';
-				} elsif ($n_slash == 1) {
-					$spfx = '';
-				} else { # nslash == 2
-					$spfx = '../../';
-				}
-			}
-		}
-		$ctx->{-spfx} = $spfx;
 	};
 
 	# split off quoted and unquoted blocks:
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 33da3244..83a8818e 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -16,6 +16,7 @@ use PublicInbox::MsgTime qw(msg_timestamp);
 sub new {
 	my ($class, $ctx, $cb) = @_;
 	$ctx->{feed_base_url} = $ctx->{ibx}->base_url($ctx->{env});
+	$ctx->{-spfx} = $ctx->{feed_base_url} if $ctx->{ibx}->{coderepo};
 	$ctx->{cb} = $cb || \&PublicInbox::GzipFilter::close;
 	$ctx->{emit_header} = 1;
 	bless $ctx, $class;