]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: support publicinbox.cgit knob
authorEric Wong <e@80x24.org>
Wed, 5 Oct 2022 22:29:41 +0000 (22:29 +0000)
committerEric Wong <e@80x24.org>
Fri, 7 Oct 2022 07:42:43 +0000 (07:42 +0000)
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
lib/PublicInbox/Cgit.pm
lib/PublicInbox/WWW.pm

index d8504e6119157e88bc4c44ec994437d12138d029..e926a27b05d5651ff1af2246833f642c21d465e4 100644 (file)
@@ -293,6 +293,32 @@ C<publicinbox.cgitbin>, but may be overridden.
 Default: basename of C<publicinbox.cgitbin>, /var/www/htdocs/cgit/
 or /usr/share/cgit/
 
+=item publicinbox.cgit
+
+Controls whether or not and how C<cgit> is used for serving coderepos.
+New in public-inbox 2.0.0 (PENDING).
+
+=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.
+
+=back
+
+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)>
index 298663c73d89f96a5ee72bc019992fc5422db238..336098caac063a30f97e711ede41fc9e918540f7 100644 (file)
@@ -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,
index 470510ae1175945588a11d003ebf32f65979ac7f..f861b192a7ee7693d88c73a311e6683dfea0c2b0 100644 (file)
@@ -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 {