]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Cgit.pm
www: support publicinbox.cgit knob
[public-inbox.git] / lib / PublicInbox / Cgit.pm
index a63f8902921726dc1cf0214712473ecb1a63a62d..336098caac063a30f97e711ede41fc9e918540f7 100644 (file)
@@ -7,6 +7,7 @@
 
 package PublicInbox::Cgit;
 use v5.12;
+use parent qw(PublicInbox::WwwCoderepo);
 use PublicInbox::GitHTTPBackend;
 use PublicInbox::Git;
 # not bothering with Exporter for a one-off
@@ -52,10 +53,7 @@ sub locate_cgit ($) {
 sub new {
        my ($class, $pi_cfg) = @_;
        my ($cgit_bin, $cgit_data) = locate_cgit($pi_cfg);
-       # TODO: support gitweb and other repository viewers?
-       if (defined(my $cgitrc = $pi_cfg->{-cgitrc_unparsed})) {
-               $pi_cfg->parse_cgitrc($cgitrc, 0);
-       }
+       $cgit_bin // return; # fall back in WWW->cgit
        my $self = bless {
                cmd => [ $cgit_bin ],
                cgit_data => $cgit_data,
@@ -63,14 +61,7 @@ sub new {
        }, $class;
 
        # some cgit repos may not be mapped to inboxes, so ensure those exist:
-       my $code_repos = $pi_cfg->{-code_repos};
-       for my $k (grep(/\Acoderepo\.(?:.+)\.dir\z/, keys %$pi_cfg)) {
-               $k = substr($k, length('coderepo.'), -length('.dir'));
-               $code_repos->{$k} //= $pi_cfg->fill_code_repo($k);
-       }
-       while (my ($nick, $repo) = each %$code_repos) {
-               $self->{"\0$nick"} = $repo;
-       }
+       PublicInbox::WwwCoderepo::prepare_coderepos($self);
        my $s = join('|', map { quotemeta } keys %{$pi_cfg->{-cgit_static}});
        $self->{static} = qr/\A($s)\z/;
        $self;
@@ -93,7 +84,7 @@ my @PASS_ENV = qw(
 my $parse_cgi_headers = \&PublicInbox::GitHTTPBackend::parse_cgi_headers;
 
 sub call {
-       my ($self, $env) = @_;
+       my ($self, $env, $ctx) = @_; # $ctx is optional, used by WWW
        my $path_info = $env->{PATH_INFO};
        my $cgit_data;
 
@@ -119,7 +110,7 @@ sub call {
        my $rdr = input_prepare($env) or return r(500);
        my $qsp = PublicInbox::Qspawn->new($self->{cmd}, $cgi_env, $rdr);
        my $limiter = $self->{pi_cfg}->limiter('-cgit');
-       $qsp->psgi_return($env, $limiter, $parse_cgi_headers);
+       $qsp->psgi_return($env, $limiter, $parse_cgi_headers, $ctx);
 }
 
 1;