]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WwwCoderepo.pm
www_coderepo: implement /$CODE_REPO/atom/ endpoint
[public-inbox.git] / lib / PublicInbox / WwwCoderepo.pm
index 01ed562b6fd35f8dedabcedc15aa175d781eca62..3c9292226b964857b6c9a12337c057f598fd2614 100644 (file)
@@ -1,7 +1,10 @@
 # Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
-# Standalone code repository viewer for users w/o cgit
+# Standalone code repository viewer for users w/o cgit.
+# This isn't intended to replicate all of cgit, but merely to be a
+# "good enough" viewer with search support and some UI hints to encourage
+# cloning + command-line usage.
 package PublicInbox::WwwCoderepo;
 use v5.12;
 use File::Temp 0.19 (); # newdir
@@ -13,6 +16,7 @@ use PublicInbox::GitAsyncCat;
 use PublicInbox::WwwStream;
 use PublicInbox::Hval qw(ascii_html);
 use PublicInbox::RepoSnapshot;
+use PublicInbox::RepoAtom;
 
 my $EACH_REF = "git for-each-ref --sort=-creatordate --format='%(HEAD)%00".
        join('%00', map { "%($_)" }
@@ -24,14 +28,27 @@ sub prepare_coderepos {
        my $pi_cfg = $self->{pi_cfg};
 
        # TODO: support gitweb and other repository viewers?
-       defined($pi_cfg->{'publicinbox.cgitrc'}) and
-               $pi_cfg->parse_cgitrc(undef, 0);
+       $pi_cfg->parse_cgitrc(undef, 0);
 
        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);
        }
+
+       # associate inboxes and extindices with coderepos for search:
+       for my $k (grep(/\Apublicinbox\.(?:.+)\.coderepo\z/, keys %$pi_cfg)) {
+               $k = substr($k, length('publicinbox.'), -length('.coderepo'));
+               my $ibx = $pi_cfg->lookup_name($k) // next;
+               $pi_cfg->repo_objs($ibx);
+               push @{$self->{-strong}}, $ibx; # strengthen {-ibxs} weakref
+       }
+       for my $k (grep(/\Aextindex\.(?:.+)\.coderepo\z/, keys %$pi_cfg)) {
+               $k = substr($k, length('extindex.'), -length('.coderepo'));
+               my $eidx = $pi_cfg->lookup_ei($k) // next;
+               $pi_cfg->repo_objs($eidx);
+               push @{$self->{-strong}}, $eidx; # strengthen {-ibxs} weakref
+       }
        while (my ($nick, $repo) = each %$code_repos) {
                $self->{"\0$nick"} = $repo;
        }
@@ -211,6 +228,11 @@ sub srv { # endpoint called by PublicInbox::WWW
                return PublicInbox::RepoSnapshot::srv($ctx, $2) // r(404);
        }
 
+       if ($path_info =~ m!\A/(.+?)/atom/(.*)\z! and
+                       ($ctx->{git} = $self->{"\0$1"})) {
+               return PublicInbox::RepoAtom::srv_atom($ctx, $2) // r(404);
+       }
+
        # enforce trailing slash:
        if ($path_info =~ m!\A/(.+?)\z! and ($git = $self->{"\0$1"})) {
                my $qs = $ctx->{env}->{QUERY_STRING};