user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/3] www: support publicinbox.cgit knob
Date: Wed,  5 Oct 2022 22:29:41 +0000	[thread overview]
Message-ID: <20221005222941.4098-4-e@80x24.org> (raw)
In-Reply-To: <20221005222941.4098-1-e@80x24.org>

For backwards-compatibility, this defaults to `first'.  When set
to `fallback', PublicInbox::WwwCoderepo is favored and cgit is
only used as a fallback.  Eventually, `rewrite' will also be
supported to rewrite cgit URLs to WwwCoderepo ones.

Of course, WwwCoderepo is still missing search and other key
features, but that's being worked on...
---
 Documentation/public-inbox-config.pod | 21 +++++++++++++++++++
 lib/PublicInbox/Cgit.pm               |  1 +
 lib/PublicInbox/WWW.pm                | 30 +++++++++++++++------------
 3 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod
index d8504e61..88403100 100644
--- a/Documentation/public-inbox-config.pod
+++ b/Documentation/public-inbox-config.pod
@@ -293,6 +293,27 @@ C<publicinbox.cgitbin>, but may be overridden.
 Default: basename of C<publicinbox.cgitbin>, /var/www/htdocs/cgit/
 or /usr/share/cgit/
 
+=item publicinbox.cgit
+
+=over 8
+
+=item * first
+
+Try using C<cgit> as the first choice, this is the default.
+
+=item * fallback
+
+Fall back to using C<cgit> only if our native, inbox-aware
+git code repository viewer doesn't recognized the URL.
+
+=item * rewrite
+
+Rewrite C<cgit> URLs for our native, inbox-aware code repository viewer.
+This implies C<fallback> for URLs the native viewer does not recognize.
+
+Default: C<first>  (C<cgit> will be used iff C<publicinbox.cgitrc>
+is set and the C<cgit> binary exists).
+
 =item publicinbox.mailEditor
 
 See L<public-inbox-edit(1)>
diff --git a/lib/PublicInbox/Cgit.pm b/lib/PublicInbox/Cgit.pm
index 298663c7..336098ca 100644
--- a/lib/PublicInbox/Cgit.pm
+++ b/lib/PublicInbox/Cgit.pm
@@ -53,6 +53,7 @@ sub locate_cgit ($) {
 sub new {
 	my ($class, $pi_cfg) = @_;
 	my ($cgit_bin, $cgit_data) = locate_cgit($pi_cfg);
+	$cgit_bin // return; # fall back in WWW->cgit
 	my $self = bless {
 		cmd => [ $cgit_bin ],
 		cgit_data => $cgit_data,
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 470510ae..f861b192 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -194,12 +194,19 @@ sub r404 {
 
 sub news_cgit_fallback ($) {
 	my ($ctx) = @_;
-	my $www = $ctx->{www};
-	my $env = $ctx->{env};
-	my $res = $www->news_www->call($env);
-	$res = $www->cgit->call($env, $ctx) if $res->[0] == 404;
+	my $res = $ctx->{www}->news_www->call($ctx->{env});
+
+	$res->[0] == 404 and ($ctx->{www}->{cgit_fallback} //= do {
+		my $c = $ctx->{www}->{pi_cfg}->{'publicinbox.cgit'} // 'first';
+		$c ne 'first' # `fallback' and `rewrite' => true
+	} // 0) and $res = $ctx->{www}->coderepo->srv($ctx);
+
 	ref($res) eq 'ARRAY' && $res->[0] == 404 and
-		$res = $www->coderepo->srv($ctx);
+		$res = $ctx->{www}->cgit->call($ctx->{env}, $ctx);
+
+	ref($res) eq 'ARRAY' && $res->[0] == 404 &&
+			!$ctx->{www}->{cgit_fallback} and
+		$res = $ctx->{www}->coderepo->srv($ctx);
 	$res;
 }
 
@@ -484,17 +491,14 @@ sub news_www {
 
 sub cgit {
 	my ($self) = @_;
-	$self->{cgit} //= do {
-		my $pi_cfg = $self->{pi_cfg};
-
-		if (defined($pi_cfg->{'publicinbox.cgitrc'})) {
+	$self->{cgit} //=
+		(defined($self->{pi_cfg}->{'publicinbox.cgitrc'}) ? do {
 			require PublicInbox::Cgit;
-			PublicInbox::Cgit->new($pi_cfg);
-		} else {
+			PublicInbox::Cgit->new($self->{pi_cfg});
+		} : undef) // do {
 			require Plack::Util;
 			Plack::Util::inline_object(call => sub { r404() });
-		}
-	}
+		};
 }
 
 sub coderepo {

  parent reply	other threads:[~2022-10-05 22:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05 22:29 [PATCH 0/3] www: configurable cgit fallback for coderepos Eric Wong
2022-10-05 22:29 ` [PATCH 1/3] www: do not call ->coderepo->srv on sub ref Eric Wong
2022-10-05 22:29 ` [PATCH 2/3] www: cgit: fall back to WwwCoderepo on 404s Eric Wong
2022-10-05 22:29 ` Eric Wong [this message]
2022-10-07  7:42   ` [squash 4/3] manpage fix (was: [PATCH 3/3] www: support publicinbox.cgit knob) Eric Wong

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

  List information: https://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20221005222941.4098-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.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.
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).