From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BBB7F1F59D for ; Thu, 12 Jan 2023 14:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1673532888; bh=l8NJ453TrwNX7B5TSNSylCJVB5C3OnEapTkPw8VXHpI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=o4xJ+VAxS7h6TvkBWyiPQ+6hqVlIw17S7GUGAHiMgVvBwpwIp9BSDdJttPfZCngmb OL84a8SzzTclXJk8FP1IYohgPQ45WcI1Cvui8j8sN9Q/+8NgoQOU8ICYWcIZVfWbIH I5hG+6z24hDz7oa2zwuMxBdTjaXETtqpgXBGKHV4= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/3] www_stream: coderepo-specific top bar Date: Thu, 12 Jan 2023 14:14:33 +0000 Message-Id: <20230112141435.1924376-2-e@80x24.org> In-Reply-To: <20230112141435.1924376-1-e@80x24.org> References: <20230112141435.1924376-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: It gets nasty when multiple, non-ALL lists point to the same coderepo, but I guess ALL exists for that. Only lightly-tested with various PSGI prefix mounts, but it seems to be working... --- lib/PublicInbox/ViewVCS.pm | 23 ++++++++++----- lib/PublicInbox/WwwCoderepo.pm | 9 +----- lib/PublicInbox/WwwStream.pm | 53 +++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index 6b641b32..7ac719bc 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -156,10 +156,14 @@ sub show_commit_start { # ->psgi_qx callback sub ibx_url_for { my ($ctx) = @_; $ctx->{ibx} and return; # fall back to $upfx - $ctx->{git} or return; + $ctx->{git} or die 'BUG: no {git}'; if (my $ALL = $ctx->{www}->{pi_cfg}->ALL) { - return $ALL->base_url // $ALL->base_url($ctx->{env}); - } elsif (my $ibx_names = $ctx->{git}->{ibx_names}) { + if (defined(my $u = $ALL->base_url($ctx->{env}))) { + return wantarray ? ($u) : $u; + } + } + my @ret; + if (my $ibx_names = $ctx->{git}->{ibx_names}) { my $by_name = $ctx->{www}->{pi_cfg}->{-by_name}; for my $name (@$ibx_names) { my $ibx = $by_name->{$name} // do { @@ -167,12 +171,13 @@ sub ibx_url_for { next; }; $ibx->isrch // next; - return defined($ibx->{url}) ? - prurl($ctx->{env}, $ibx->{url}) : - "../../../$name/"; + my $u = defined($ibx->{url}) ? + prurl($ctx->{env}, $ibx->{url}) : $name; + $u .= '/' if substr($u, -1) ne '/'; + push @ret, $u; } } - undef; + wantarray ? (@ret) : $ret[0]; } sub cmt_finalize { @@ -253,8 +258,10 @@ EOM my $ibx_url = ibx_url_for($ctx); my $alt; if (defined $ibx_url) { + $alt = " `$ibx_url'"; + $ibx_url =~ m!://! or + substr($ibx_url, 0, 0, '../../../'); $ibx_url = ascii_html($ibx_url); - $alt = ' '.$ibx_url; } else { $ibx_url = $upfx; $alt = ''; diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm index e89a6456..2fba0cd0 100644 --- a/lib/PublicInbox/WwwCoderepo.pm +++ b/lib/PublicInbox/WwwCoderepo.pm @@ -79,14 +79,7 @@ sub summary_finish { $tip_html .= ' '.ascii_html($tip).' --'; } print $zfh < -about heads tags - -\$ git log --pretty=format:'%h %s (%cs)%d'$tip_html +
\$ git log --pretty=format:'%h %s (%cs)%d'$tip_html
 EOM
 	for (@r) {
 		my $d; # decorations
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 59edad5d..8c40096a 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -38,9 +38,60 @@ sub async_eml { # for async_blob_cb
 	$ctx->write($ctx->{cb}->($ctx, $eml));
 }
 
+sub html_repo_top ($) {
+	my ($ctx) = @_;
+	my $git = $ctx->{git};
+	my $desc = ascii_html($git->description);
+	my $title = delete($ctx->{-title_html}) // $desc;
+	my $upfx = $ctx->{-upfx} // '';
+	my $atom = $ctx->{-atom} // (substr($upfx, -1) eq '/' ?
+					"${upfx}atom/" : "$upfx/atom/");
+	my $top = ascii_html($git->{nick});
+	$top = qq($top) if length($upfx);
+	$top .= <about / heads / tags
+$desc
+EOM
+	my @url = PublicInbox::ViewVCS::ibx_url_for($ctx);
+	if (@url) {
+		$ctx->{-has_srch} = 1;
+		my $base_url = base_url($ctx);
+		my ($pfx, $sfx) = ($base_url =~ m!\A(https?://[^/]+/)(.*)\z!i);
+		my $iupfx = '../' x (($sfx =~ tr!/!/!) + 1);
+		$pfx = ascii_html($pfx);
+		$pfx = qr/\A\Q$pfx\E/i;
+		my $tmp = $top;
+		$top = '';
+		my ($s, $u, $same_host);
+		my $q_val = delete($ctx->{-q_value_html}) // '';
+		$q_val = qq(\nvalue="$q_val") if $q_val ne '';
+		for (@url) {
+			$u = $s = ascii_html($_);
+			substr($u, 0, 0, $iupfx) if $u !~ m!://!;
+			$s =~ s!$pfx!!;
+			$s =~ s!/\z!!;
+			$top .= qq{
$tmp} .
+				qq{} .
+				qq{} .
+				q{
}; + $tmp = ''; + } + } else { + $top = "
$top
"; + } + "$title" . + qq() . + $ctx->{www}->style($upfx) . + ''.$top; +} + sub html_top ($) { my ($ctx) = @_; - my $ibx = $ctx->{ibx} // $ctx->{git}; + my $ibx = $ctx->{ibx} // return html_repo_top($ctx); my $desc = ascii_html($ibx->description); my $title = delete($ctx->{-title_html}) // $desc; my $upfx = $ctx->{-upfx} || '';