user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/2] www: solver linkification fixes
@ 2022-09-10 20:10 Eric Wong
  2022-09-10 20:10 ` [PATCH 1/2] view: fix solver links with multiple messages Eric Wong
  2022-09-10 20:10 ` [PATCH 2/2] solver: do not show redundant URLs in log Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2022-09-10 20:10 UTC (permalink / raw)
  To: meta

Some things I noticed with /all/, solver, and redundant
messages.  Hunk header links for /all/ should point to
the right place, now; and the debug log output should
no longer have redundant URLs.

And deletions > insertions makes me happy :>

Eric Wong (2):
  view: fix solver links with multiple messages
  solver: do not show redundant URLs in log

 lib/PublicInbox/Feed.pm          |  1 +
 lib/PublicInbox/SolverGit.pm     |  5 +++--
 lib/PublicInbox/View.pm          | 20 ++------------------
 lib/PublicInbox/WwwAtomStream.pm |  1 +
 4 files changed, 7 insertions(+), 20 deletions(-)

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

* [PATCH 1/2] view: fix solver links with multiple messages
  2022-09-10 20:10 [PATCH 0/2] www: solver linkification fixes Eric Wong
@ 2022-09-10 20:10 ` Eric Wong
  2022-09-10 20:10 ` [PATCH 2/2] solver: do not show redundant URLs in log Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2022-09-10 20:10 UTC (permalink / raw)
  To: meta

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} = '<pre>';
 	$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;

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

* [PATCH 2/2] solver: do not show redundant URLs in log
  2022-09-10 20:10 [PATCH 0/2] www: solver linkification fixes Eric Wong
  2022-09-10 20:10 ` [PATCH 1/2] view: fix solver links with multiple messages Eric Wong
@ 2022-09-10 20:10 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2022-09-10 20:10 UTC (permalink / raw)
  To: meta

Messages in /all/ can get duplicated at times due to
list-appended signatures or buggy/malicious clients.
They'll all show up based on /$INBOX/$MSGID/,
so deduplicate the URLs to avoid noise.
---
 lib/PublicInbox/SolverGit.pm | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index ac655f34..b723b48a 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -554,8 +554,9 @@ sub extract_diffs_done {
 	my $diffs = delete $self->{tmp_diffs};
 	if (scalar @$diffs) {
 		unshift @{$self->{patches}}, @$diffs;
-		dbg($self, "found $want->{oid_b} in " .  join(" ||\n\t",
-			map { di_url($self, $_) } @$diffs));
+		my %seen; # List::Util::uniq requires Perl 5.26+ :<
+		my @u = grep { !$seen{$_}++ } map { di_url($self, $_) } @$diffs;
+		dbg($self, "found $want->{oid_b} in " .  join(" ||\n\t", @u));
 		++$self->{nr_p};
 
 		# good, we can find a path to the oid we $want, now

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

end of thread, other threads:[~2022-09-10 20:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-10 20:10 [PATCH 0/2] www: solver linkification fixes Eric Wong
2022-09-10 20:10 ` [PATCH 1/2] view: fix solver links with multiple messages Eric Wong
2022-09-10 20:10 ` [PATCH 2/2] solver: do not show redundant URLs in log Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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