about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-16 23:02:16 -0800
committerEric Wong <e@80x24.org>2021-03-17 19:03:13 +0000
commita5968dc059f655a9ac62f1b8bf0bed2b90080b02 (patch)
treead57560f39f94358d93f2d4d492169e8f994f65a
parentbe940983157a1f8bd353cb1891f6971645c73e5d (diff)
downloadpublic-inbox-a5968dc059f655a9ac62f1b8bf0bed2b90080b02.tar.gz
Extsearch objects are duck-types of Inbox objects, and
are capable of supporting code repos all the same.
-rw-r--r--lib/PublicInbox/Config.pm48
-rw-r--r--lib/PublicInbox/View.pm5
-rw-r--r--lib/PublicInbox/WWW.pm2
-rw-r--r--lib/PublicInbox/WwwStream.pm2
-rw-r--r--lib/PublicInbox/WwwText.pm2
-rw-r--r--t/config.t2
6 files changed, 41 insertions, 20 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 113975dd..1037c884 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -355,6 +355,12 @@ sub _fill_code_repo {
         $git;
 }
 
+sub get_all {
+        my ($self, $key) = @_;
+        my $v = $self->{$key} // return;
+        _array($v);
+}
+
 sub git_bool {
         my ($val) = $_[-1]; # $_[0] may be $self, or $val
         if ($val =~ /\A(?:false|no|off|[\-\+]?(?:0x)?0+)\z/i) {
@@ -384,6 +390,34 @@ sub _one_val {
         $v->[-1];
 }
 
+sub repo_objs {
+        my ($self, $ibxish) = @_;
+        my $ibx_code_repos = $ibxish->{coderepo} or return;
+        $ibxish->{-repo_objs} //= do {
+                my $code_repos = $self->{-code_repos};
+                my @repo_objs;
+                for my $nick (@$ibx_code_repos) {
+                        my @parts = split(m!/!, $nick);
+                        for (@parts) {
+                                @parts = () unless valid_foo_name($_);
+                        }
+                        unless (@parts) {
+                                warn "invalid coderepo name: `$nick'\n";
+                                next;
+                        }
+                        my $repo = $code_repos->{$nick} //=
+                                                _fill_code_repo($self, $nick);
+                        push @repo_objs, $repo if $repo;
+                }
+                if (scalar @repo_objs) {
+                        \@repo_objs;
+                } else {
+                        delete $ibxish->{coderepo};
+                        undef;
+                }
+        }
+}
+
 sub _fill_ibx {
         my ($self, $name) = @_;
         my $pfx = "publicinbox.$name";
@@ -467,20 +501,6 @@ sub _fill_ibx {
                 $ibx->{-no_obfuscate_re} = $self->{-no_obfuscate_re};
                 fill_all($self); # noop to populate -no_obfuscate
         }
-        if (my $ibx_code_repos = $ibx->{coderepo}) {
-                my $code_repos = $self->{-code_repos};
-                my $repo_objs = $ibx->{-repo_objs} = [];
-                foreach my $nick (@$ibx_code_repos) {
-                        my @parts = split(m!/!, $nick);
-                        my $valid = 0;
-                        $valid += valid_foo_name($_) foreach (@parts);
-                        $valid == scalar(@parts) or next;
-
-                        my $repo = $code_repos->{$nick} //=
-                                                _fill_code_repo($self, $nick);
-                        push @$repo_objs, $repo if $repo;
-                }
-        }
         if (my $es = ALL($self)) {
                 require PublicInbox::Isearch;
                 $ibx->{isrch} = PublicInbox::Isearch->new($ibx, $es);
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index eee6ae33..f4f6da11 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -591,8 +591,9 @@ sub add_text_body { # callback for each_part
                 $diff = 1;
                 delete $ctx->{-long_path};
                 my $spfx;
-                if ($ibx->{-repo_objs}) {
-                        if (index($upfx, '//') >= 0) { # absolute URL (Atom feeds)
+                # absolute URL (Atom feeds)
+                if ($ibx->{coderepo}) {
+                        if (index($upfx, '//') >= 0) {
                                 $spfx = $upfx;
                                 $spfx =~ s!/([^/]*)/\z!/!;
                         } else {
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 500021d4..456692a3 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -309,7 +309,7 @@ sub get_text {
 sub get_vcs_object ($$$;$) {
         my ($ctx, $inbox, $oid, $filename) = @_;
         my $r404 = invalid_inbox($ctx, $inbox);
-        return $r404 if $r404;
+        return $r404 if $r404 || !$ctx->{www}->{pi_cfg}->repo_objs($ctx->{ibx});
         require PublicInbox::ViewVCS;
         PublicInbox::ViewVCS::show($ctx, $oid, $filename);
 }
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 1178a3c9..be9e762e 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -84,7 +84,7 @@ sub coderepos ($) {
         my $upfx = ($ctx->{-upfx} // ''). '../';
         my @ret;
         for my $cr_name (@$cr) {
-                my $urls = $cfg->{"coderepo.$cr_name.cgiturl"} // next;
+                my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl") // next;
                 $ret[0] //= <<EOF;
 code repositories for the project(s) associated with this inbox:
 EOF
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index 9f46c6a6..76a95a6b 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -191,7 +191,7 @@ EOF
 EOF
                 my $pi_cfg = $ctx->{www}->{pi_cfg};
                 for my $cr_name (@$cr) {
-                        my $urls = $pi_cfg->{"coderepo.$cr_name.cgiturl"};
+                        my $urls = $pi_cfg->get_all("coderepo.$cr_name.cgiturl");
                         my $path = "/path/to/$cr_name";
                         $cr_name = dq_escape($cr_name);
 
diff --git a/t/config.t b/t/config.t
index 06a105c1..73527ec2 100644
--- a/t/config.t
+++ b/t/config.t
@@ -212,7 +212,7 @@ EOF
         my $cfg = PublicInbox::Config->new(\$str);
         my $t1 = $cfg->lookup_name('test1');
         my $t2 = $cfg->lookup_name('test2');
-        is($t1->{-repo_objs}->[0], $t2->{-repo_objs}->[0],
+        is($cfg->repo_objs($t1)->[0], $cfg->repo_objs($t2)->[0],
                 'inboxes share ::Git object');
 }