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 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 788C31F523 for ; Wed, 5 Oct 2022 22:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1665008981; bh=Rw8aHNJxHiT3m/fx0BI/DAYroZkZPiDTY09hU47OazU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KlCrwt67ZXHol2ZtRKQFBP35mN9/2/3OecXMmQcnYQSfozGC1RY+MfrRqqEjBpHU0 jpXj/ViNstDSEjD0uuWNJReWIljKA48hUlvWC+LKW3ooRX3S8cQlUQyTlWP9l9mD9w a/qfoutoh6DKBbTjRmqJQTz8BuvxjRe7YCPqI1dc= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/3] www: support publicinbox.cgit knob Date: Wed, 5 Oct 2022 22:29:41 +0000 Message-Id: <20221005222941.4098-4-e@80x24.org> In-Reply-To: <20221005222941.4098-1-e@80x24.org> References: <20221005222941.4098-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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, but may be overridden. Default: basename of C, /var/www/htdocs/cgit/ or /usr/share/cgit/ +=item publicinbox.cgit + +=over 8 + +=item * first + +Try using C as the first choice, this is the default. + +=item * fallback + +Fall back to using C only if our native, inbox-aware +git code repository viewer doesn't recognized the URL. + +=item * rewrite + +Rewrite C URLs for our native, inbox-aware code repository viewer. +This implies C for URLs the native viewer does not recognize. + +Default: C (C will be used iff C +is set and the C binary exists). + =item publicinbox.mailEditor See L 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 {