user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/5] config: lazy-load coderepos, support extindex
Date: Tue, 16 Mar 2021 23:02:16 -0800	[thread overview]
Message-ID: <20210317070218.7971-4-e@80x24.org> (raw)
In-Reply-To: <20210317070218.7971-1-e@80x24.org>

Extsearch objects are duck-types of Inbox objects, and
are capable of supporting code repos all the same.
---
 lib/PublicInbox/Config.pm    | 48 +++++++++++++++++++++++++-----------
 lib/PublicInbox/View.pm      |  5 ++--
 lib/PublicInbox/WWW.pm       |  2 +-
 lib/PublicInbox/WwwStream.pm |  2 +-
 lib/PublicInbox/WwwText.pm   |  2 +-
 t/config.t                   |  2 +-
 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');
 }
 

  parent reply	other threads:[~2021-03-17  7:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17  7:02 [PATCH 0/5] www: extindex stuff Eric Wong
2021-03-17  7:02 ` [PATCH 1/5] www_stream: add trailing slash for help and color links Eric Wong
2021-03-17  7:02 ` [PATCH 2/5] extindex: add some validation and config knobs for WWW Eric Wong
2021-03-17  7:02 ` Eric Wong [this message]
2021-03-17  7:02 ` [PATCH 4/5] www: improve visibility of coderepos Eric Wong
2021-03-17  7:02 ` [PATCH 5/5] tests: show lsof output on deleted-file-check failures Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210317070218.7971-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).