dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] www: cgit: support non-standard cgitrc locations
Date: Tue, 13 Feb 2024 08:45:55 +0000	[thread overview]
Message-ID: <20240213084555.3218420-1-e@80x24.org> (raw)

If publicinbox.cgitrc is set in the config file, we'll ensure
cgit sees it as CGIT_CONFIG since the configured
publicinbox.cgitrc knob may not be the default path the cgit.cgi
binary was configured to use.

Furthermore, we'll respect CGIT_CONFIG in the environment if
publicinbox.cgitrc is unset in the config file at -httpd/-netd
startup.
---
 lib/PublicInbox/Cgit.pm   | 12 +++++-------
 lib/PublicInbox/Config.pm |  3 ++-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/Cgit.pm b/lib/PublicInbox/Cgit.pm
index 10cad57a..78fc9ca0 100644
--- a/lib/PublicInbox/Cgit.pm
+++ b/lib/PublicInbox/Cgit.pm
@@ -58,6 +58,7 @@ sub new {
 		cmd => [ $cgit_bin ],
 		cgit_data => $cgit_data,
 		pi_cfg => $pi_cfg,
+		cgitrc => $pi_cfg->{'publicinbox.cgitrc'} // $ENV{CGIT_CONFIG},
 	}, $class;
 
 	# some cgit repos may not be mapped to inboxes, so ensure those exist:
@@ -100,15 +101,12 @@ sub call {
 		return PublicInbox::WwwStatic::response($env, [], $f);
 	}
 
-	my $cgi_env = { PATH_INFO => $path_info };
-	foreach (@PASS_ENV) {
-		my $v = $env->{$_} // next;
-		$cgi_env->{$_} = $v;
-	}
-	$cgi_env->{'HTTPS'} = 'on' if $env->{'psgi.url_scheme'} eq 'https';
+	my %cgi_env = (CGIT_CONFIG => $self->{cgitrc}, PATH_INFO => $path_info);
+	@cgi_env{@PASS_ENV} = @$env{@PASS_ENV}; # spawn ignores undef vals
+	$cgi_env{HTTPS} = 'on' if $env->{'psgi.url_scheme'} eq 'https';
 
 	my $rdr = input_prepare($env) or return r(500);
-	my $qsp = PublicInbox::Qspawn->new($self->{cmd}, $cgi_env, $rdr);
+	my $qsp = PublicInbox::Qspawn->new($self->{cmd}, \%cgi_env, $rdr);
 	my $limiter = $self->{pi_cfg}->limiter('-cgit');
 	$qsp->psgi_yield($env, $limiter, $parse_cgi_headers, $ctx);
 }
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index b8d3c485..607197f6 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -305,7 +305,8 @@ sub apply_cgit_scan_path {
 
 sub parse_cgitrc {
 	my ($self, $cgitrc, $nesting) = @_;
-	$cgitrc //= $self->{'publicinbox.cgitrc'} // return;
+	$cgitrc //= $self->{'publicinbox.cgitrc'} //
+			$ENV{CGIT_CONFIG} // return;
 	if ($nesting == 0) {
 		# defaults:
 		my %s = map { $_ => 1 } qw(/cgit.css /cgit.png

                 reply	other threads:[~2024-02-13  8:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=20240213084555.3218420-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.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).