user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/5] www: extindex stuff
@ 2021-03-17  7:02 Eric Wong
  2021-03-17  7:02 ` [PATCH 1/5] www_stream: add trailing slash for help and color links Eric Wong
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eric Wong @ 2021-03-17  7:02 UTC (permalink / raw)
  To: meta

extindex.{url,coderepo,infourl} knobs should all be working,
altid may work, but might not be useful.  coderepo visibility
is also improved.

Eric Wong (5):
  www_stream: add trailing slash for help and color links
  extindex: add some validation and config knobs for WWW
  config: lazy-load coderepos, support extindex
  www: improve visibility of coderepos
  tests: show lsof output on deleted-file-check failures

 MANIFEST                         |   1 +
 lib/PublicInbox/Config.pm        | 122 +++++++++++++++++++------------
 lib/PublicInbox/ExtSearch.pm     |   2 +-
 lib/PublicInbox/Git.pm           |   2 +-
 lib/PublicInbox/TestCommon.pm    |  28 ++++++-
 lib/PublicInbox/View.pm          |   5 +-
 lib/PublicInbox/WWW.pm           |   2 +-
 lib/PublicInbox/WwwAtomStream.pm |   6 +-
 lib/PublicInbox/WwwStream.pm     |  27 ++++---
 lib/PublicInbox/WwwText.pm       |   2 +-
 t/config.t                       |   6 +-
 t/extindex-psgi.t                |  48 ++++++++++++
 t/httpd-corner.t                 |   3 +-
 t/nntpd.t                        |   5 +-
 t/psgi_v2.t                      |  30 ++------
 15 files changed, 191 insertions(+), 98 deletions(-)
 create mode 100644 t/extindex-psgi.t

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] www_stream: add trailing slash for help and color links
  2021-03-17  7:02 [PATCH 0/5] www: extindex stuff Eric Wong
@ 2021-03-17  7:02 ` Eric Wong
  2021-03-17  7:02 ` [PATCH 2/5] extindex: add some validation and config knobs for WWW Eric Wong
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2021-03-17  7:02 UTC (permalink / raw)
  To: meta

This saves clients a redirect
---
 lib/PublicInbox/WwwStream.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index bcf2ecec..1178a3c9 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -40,8 +40,8 @@ sub html_top ($) {
 	my $desc = ascii_html($ibx->description);
 	my $title = delete($ctx->{-title_html}) // $desc;
 	my $upfx = $ctx->{-upfx} || '';
-	my $help = $upfx.'_/text/help';
-	my $color = $upfx.'_/text/color';
+	my $help = $upfx.'_/text/help/';
+	my $color = $upfx.'_/text/color/';
 	my $atom = $ctx->{-atom} || $upfx.'new.atom';
 	my $top = "<b>$desc</b>";
 	if (my $t_max = $ctx->{-t_max}) {

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/5] extindex: add some validation and config knobs for WWW
  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 ` Eric Wong
  2021-03-17  7:02 ` [PATCH 3/5] config: lazy-load coderepos, support extindex Eric Wong
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2021-03-17  7:02 UTC (permalink / raw)
  To: meta

We'll try to share a bit more configuration with
extindex entries for WWW PSGI usage.
---
 MANIFEST                         |  1 +
 lib/PublicInbox/Config.pm        | 76 +++++++++++++++++---------------
 lib/PublicInbox/ExtSearch.pm     |  2 +-
 lib/PublicInbox/TestCommon.pm    | 28 +++++++++++-
 lib/PublicInbox/WwwAtomStream.pm |  6 ++-
 t/config.t                       |  4 +-
 t/extindex-psgi.t                | 48 ++++++++++++++++++++
 t/psgi_v2.t                      | 30 +++----------
 8 files changed, 130 insertions(+), 65 deletions(-)
 create mode 100644 t/extindex-psgi.t

diff --git a/MANIFEST b/MANIFEST
index 49c10d62..775de5cd 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -324,6 +324,7 @@ t/eml.t
 t/eml_content_disposition.t
 t/eml_content_type.t
 t/epoll.t
+t/extindex-psgi.t
 t/extsearch.t
 t/fail-bin/spamc
 t/fake_inotify.t
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 87a03fd3..113975dd 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -88,12 +88,12 @@ sub lookup_list_id {
 
 sub lookup_name ($$) {
 	my ($self, $name) = @_;
-	$self->{-by_name}->{$name} // _fill($self, "publicinbox.$name");
+	$self->{-by_name}->{$name} // _fill_ibx($self, $name);
 }
 
 sub lookup_ei {
 	my ($self, $name) = @_;
-	$self->{-ei_by_name}->{$name} //= _fill_ei($self, "extindex.$name");
+	$self->{-ei_by_name}->{$name} //= _fill_ei($self, $name);
 }
 
 # special case for [extindex "all"]
@@ -167,8 +167,8 @@ sub git_config_dump {
 	$rv;
 }
 
-sub valid_inbox_name ($) {
-	my ($name) = @_;
+sub valid_foo_name ($;$) {
+	my ($name, $pfx) = @_;
 
 	# Similar rules found in git.git/remote.c::valid_remote_nick
 	# and git.git/refs.c::check_refname_component
@@ -176,6 +176,7 @@ sub valid_inbox_name ($) {
 	if ($name eq '' || $name =~ /\@\{/ ||
 	    $name =~ /\.\./ || $name =~ m![/:\?\[\]\^~\s\f[:cntrl:]\*]! ||
 	    $name =~ /\A\./ || $name =~ /\.\z/) {
+		warn "invalid $pfx name: `$name'\n" if $pfx;
 		return 0;
 	}
 
@@ -375,26 +376,26 @@ sub rel2abs_collapsed {
 	Cwd::abs_path($p);
 }
 
-sub _fill {
-	my ($self, $pfx) = @_;
-	my $ibx = {};
+sub _one_val {
+	my ($self, $pfx, $k) = @_;
+	my $v = $self->{"$pfx.$k"} // return;
+	return $v if !ref($v);
+	warn "W: $pfx.$k has multiple values, only using `$v->[-1]'\n";
+	$v->[-1];
+}
 
+sub _fill_ibx {
+	my ($self, $name) = @_;
+	my $pfx = "publicinbox.$name";
+	my $ibx = {};
 	for my $k (qw(watch nntpserver)) {
 		my $v = $self->{"$pfx.$k"};
 		$ibx->{$k} = $v if defined $v;
 	}
 	for my $k (qw(filter inboxdir newsgroup replyto httpbackendmax feedmax
 			indexlevel indexsequentialshard)) {
-		if (defined(my $v = $self->{"$pfx.$k"})) {
-			if (ref($v) eq 'ARRAY') {
-				warn <<EOF;
-W: $pfx.$k has multiple values, only using `$v->[-1]'
-EOF
-				$ibx->{$k} = $v->[-1];
-			} else {
-				$ibx->{$k} = $v;
-			}
-		}
+		my $v = _one_val($self, $pfx, $k) // next;
+		$ibx->{$k} = $v;
 	}
 
 	# "mainrepo" is backwards compatibility:
@@ -403,9 +404,8 @@ EOF
 		warn "E: `$dir' must not contain `\\n'\n";
 		return;
 	}
-	foreach my $k (qw(obfuscate)) {
-		my $v = $self->{"$pfx.$k"};
-		defined $v or next;
+	for my $k (qw(obfuscate)) {
+		my $v = $self->{"$pfx.$k"} // next;
 		if (defined(my $bval = git_bool($v))) {
 			$ibx->{$k} = $bval;
 		} else {
@@ -414,19 +414,13 @@ EOF
 	}
 	# TODO: more arrays, we should support multi-value for
 	# more things to encourage decentralization
-	foreach my $k (qw(address altid nntpmirror coderepo hide listid url
+	for my $k (qw(address altid nntpmirror coderepo hide listid url
 			infourl watchheader)) {
-		if (defined(my $v = $self->{"$pfx.$k"})) {
-			$ibx->{$k} = _array($v);
-		}
-	}
-
-	my $name = substr($pfx, length('publicinbox.'));
-	if (!valid_inbox_name($name)) {
-		warn "invalid inbox name: '$name'\n";
-		return;
+		my $v = $self->{"$pfx.$k"} // next;
+		$ibx->{$k} = _array($v);
 	}
 
+	return unless valid_foo_name($name, 'publicinbox');
 	$ibx->{name} = $name;
 	$ibx->{-pi_cfg} = $self;
 	$ibx = PublicInbox::Inbox->new($ibx);
@@ -473,14 +467,13 @@ EOF
 		$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_inbox_name($_) foreach (@parts);
+			$valid += valid_foo_name($_) foreach (@parts);
 			$valid == scalar(@parts) or next;
 
 			my $repo = $code_repos->{$nick} //=
@@ -496,10 +489,23 @@ EOF
 }
 
 sub _fill_ei ($$) {
-	my ($self, $pfx) = @_;
+	my ($self, $name) = @_;
 	eval { require PublicInbox::ExtSearch } or return;
-	my $d = $self->{"$pfx.topdir"};
-	defined($d) && -d $d ? PublicInbox::ExtSearch->new($d) : undef;
+	my $pfx = "extindex.$name";
+	my $d = $self->{"$pfx.topdir"} // return;
+	-d $d or return;
+	my $es = PublicInbox::ExtSearch->new($d);
+	for my $k (qw(indexlevel indexsequentialshard)) {
+		my $v = _one_val($self, $pfx, $k) // next;
+		$es->{$k} = $v;
+	}
+	for my $k (qw(altid coderepo hide url infourl)) {
+		my $v = $self->{"$pfx.$k"} // next;
+		$es->{$k} = _array($v);
+	}
+	return unless valid_foo_name($name, 'extindex');
+	$es->{name} = $name;
+	$es;
 }
 
 sub urlmatch {
diff --git a/lib/PublicInbox/ExtSearch.pm b/lib/PublicInbox/ExtSearch.pm
index 8ba4d396..c2cfc338 100644
--- a/lib/PublicInbox/ExtSearch.pm
+++ b/lib/PublicInbox/ExtSearch.pm
@@ -107,10 +107,10 @@ sub description {
 
 sub cloneurl { [] } # TODO
 
-sub base_url { 'https://example.com/TODO/' }
 sub nntp_url { [] }
 
 no warnings 'once';
+*base_url = \&PublicInbox::Inbox::base_url;
 *smsg_eml = \&PublicInbox::Inbox::smsg_eml;
 *smsg_by_mid = \&PublicInbox::Inbox::smsg_by_mid;
 *msg_by_mid = \&PublicInbox::Inbox::msg_by_mid;
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index c2d07e59..0d15514e 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -15,7 +15,8 @@ BEGIN {
 	@EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
 		run_script start_script key2sub xsys xsys_e xqx eml_load tick
 		have_xapian_compact json_utf8 setup_public_inboxes create_inbox
-		tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt);
+		tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt
+		test_httpd);
 	require Test::More;
 	my @methods = grep(!/\W/, @Test::More::EXPORT);
 	eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
@@ -636,6 +637,31 @@ sub create_inbox ($$;@) {
 	$ibx;
 }
 
+sub test_httpd ($$;$) {
+	my ($env, $client, $skip) = @_;
+	for (qw(PI_CONFIG TMPDIR)) {
+		$env->{$_} or BAIL_OUT "$_ unset";
+	}
+	SKIP: {
+		require_mods(qw(Plack::Test::ExternalServer), $skip // 1);
+		my $sock = tcp_server() or die;
+		my ($out, $err) = map { "$env->{TMPDIR}/std$_.log" } qw(out err);
+		my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
+		my $td = start_script($cmd, $env, { 3 => $sock });
+		my ($h, $p) = tcp_host_port($sock);
+		local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
+		Plack::Test::ExternalServer::test_psgi(client => $client);
+		$td->join('TERM');
+		open my $fh, '<', $err or BAIL_OUT $!;
+		my $e = do { local $/; <$fh> };
+		if ($e =~ s/^Plack::Middleware::ReverseProxy missing,\n//gms) {
+			$e =~ s/^URL generation for redirects .*\n//gms;
+		}
+		is($e, '', 'no errors');
+	}
+};
+
+
 package PublicInboxTestProcess;
 use strict;
 
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 361e61f6..f60251b7 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -100,7 +100,11 @@ sub atom_header {
 	} else {
 		$title = title_tag($ibx->description);
 		$self_url .= 'new.atom';
-		$page_id = "mailto:$ibx->{-primary_address}";
+		if (defined(my $addr = $ibx->{-primary_address})) {
+			$page_id = "mailto:$addr";
+		} else {
+			$page_id = to_uuid($self_url);
+		}
 	}
 	qq(<?xml version="1.0" encoding="us-ascii"?>\n) .
 	qq(<feed\nxmlns="http://www.w3.org/2005/Atom"\n) .
diff --git a/t/config.t b/t/config.t
index fe684106..06a105c1 100644
--- a/t/config.t
+++ b/t/config.t
@@ -159,7 +159,7 @@ my $xre = join('|', keys %X);
 for my $s (@invalid) {
 	my $d = $s;
 	$d =~ s/($xre)/$X{$1}/g;
-	ok(!PublicInbox::Config::valid_inbox_name($s), "`$d' name rejected");
+	ok(!PublicInbox::Config::valid_foo_name($s), "`$d' name rejected");
 }
 
 # obviously-valid examples
@@ -175,7 +175,7 @@ my @valid = qw(a a@example a@example.com);
 # '!', '$', '=', '+'
 push @valid, qw[bang! ca$h less< more> 1% (parens) &more eql= +plus], '#hash';
 for my $s (@valid) {
-	ok(PublicInbox::Config::valid_inbox_name($s), "`$s' name accepted");
+	ok(PublicInbox::Config::valid_foo_name($s), "`$s' name accepted");
 }
 
 {
diff --git a/t/extindex-psgi.t b/t/extindex-psgi.t
new file mode 100644
index 00000000..6f62b5a0
--- /dev/null
+++ b/t/extindex-psgi.t
@@ -0,0 +1,48 @@
+#!perl -w
+# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use v5.10.1;
+use PublicInbox::TestCommon;
+use PublicInbox::Config;
+use File::Copy qw(cp);
+use IO::Handle ();
+require_git(2.6);
+require_mods(qw(json DBD::SQLite Search::Xapian
+		HTTP::Request::Common Plack::Test URI::Escape Plack::Builder));
+use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
+require PublicInbox::WWW;
+my ($ro_home, $cfg_path) = setup_public_inboxes;
+my ($tmpdir, $for_destroy) = tmpdir;
+my $home = "$tmpdir/home";
+mkdir $home or BAIL_OUT $!;
+mkdir "$home/.public-inbox" or BAIL_OUT $!;
+my $pi_config = "$home/.public-inbox/config";
+cp("$ro_home/.public-inbox/config", $pi_config) or BAIL_OUT;
+my $env = { HOME => $home };
+run_script([qw(-extindex --all), "$tmpdir/eidx"], $env) or BAIL_OUT;
+{
+	open my $cfgfh, '>', $pi_config or BAIL_OUT;
+	$cfgfh->autoflush(1);
+	print $cfgfh <<EOM or BAIL_OUT;
+[extindex "all"]
+	topdir = $tmpdir/eidx
+	url = http://bogus.example.com/all
+EOM
+}
+my $www = PublicInbox::WWW->new(PublicInbox::Config->new($pi_config));
+my $client = sub {
+	my ($cb) = @_;
+	my $res = $cb->(GET('/all/'));
+	is($res->code, 200, '/all/ good');
+	$res = $cb->(GET('/all/new.atom', Host => 'usethis.example.com'));
+	like($res->content, qr!http://usethis\.example\.com/!s,
+		'Host: header respected in Atom feed');
+	unlike($res->content, qr!http://bogus\.example\.com/!s,
+		'default URL ignored with different host header');
+};
+test_psgi(sub { $www->call(@_) }, $client);
+%$env = (%$env, TMPDIR => $tmpdir, PI_CONFIG => $pi_config);
+test_httpd($env, $client);
+
+done_testing;
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 487317b6..1f190708 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -56,27 +56,6 @@ EOF
 	close $fh or BAIL_OUT;
 }
 
-my $run_httpd = sub {
-	my ($client, $skip) = @_;
-	SKIP: {
-		require_mods(qw(Plack::Test::ExternalServer), $skip);
-		my $env = { PI_CONFIG => $cfgpath };
-		my $sock = tcp_server() or die;
-		my ($out, $err) = map { "$tmpdir/std$_.log" } qw(out err);
-		my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
-		my $td = start_script($cmd, $env, { 3 => $sock });
-		my ($h, $p) = tcp_host_port($sock);
-		local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
-		Plack::Test::ExternalServer::test_psgi(client => $client);
-		$td->join('TERM');
-		open my $fh, '<', $err or BAIL_OUT $!;
-		my $e = do { local $/; <$fh> };
-		if ($e =~ s/^Plack::Middleware::ReverseProxy missing,\n//gms) {
-			$e =~ s/^URL generation for redirects .*\n//gms;
-		}
-		is($e, '', 'no errors');
-	}
-};
 my $msg = $ibx->msg_by_mid('a-mid@b');
 like($$msg, qr/\AFrom oldbug/s,
 	'"From_" line stored to test old bug workaround');
@@ -115,7 +94,8 @@ my $client0 = sub {
 		'new.html ordering is chronological');
 };
 test_psgi(sub { $www->call(@_) }, $client0);
-$run_httpd->($client0, 9);
+my $env = { TMPDIR => $tmpdir, PI_CONFIG => $cfgpath };
+test_httpd($env, $client0, 9);
 
 $eml->header_set('Message-ID', 'a-mid@b');
 $eml->body_set("hello ghosts\n");
@@ -225,7 +205,7 @@ my $client1 = sub {
 };
 
 test_psgi(sub { $www->call(@_) }, $client1);
-$run_httpd->($client1, 38);
+test_httpd($env, $client1, 38);
 
 {
 	my $exp = [ qw(<a-mid@b> <reuse@mid>) ];
@@ -267,7 +247,7 @@ my $client2 = sub {
 };
 
 test_psgi(sub { $www->call(@_) }, $client2);
-$run_httpd->($client2, 8);
+test_httpd($env, $client2, 8);
 {
 	# ensure conflicted attachments can be resolved
 	local $SIG{__WARN__} = sub {};
@@ -298,6 +278,6 @@ my $client3 = sub {
 	is_deeply(\@warn, [], 'no warnings on YYYYMMDD only');
 };
 test_psgi(sub { $www->call(@_) }, $client3);
-$run_httpd->($client3, 4);
+test_httpd($env, $client3, 4);
 
 done_testing;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/5] config: lazy-load coderepos, support extindex
  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
  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
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2021-03-17  7:02 UTC (permalink / raw)
  To: meta

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');
 }
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/5] www: improve visibility of coderepos
  2021-03-17  7:02 [PATCH 0/5] www: extindex stuff Eric Wong
                   ` (2 preceding siblings ...)
  2021-03-17  7:02 ` [PATCH 3/5] config: lazy-load coderepos, support extindex Eric Wong
@ 2021-03-17  7:02 ` Eric Wong
  2021-03-17  7:02 ` [PATCH 5/5] tests: show lsof output on deleted-file-check failures Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2021-03-17  7:02 UTC (permalink / raw)
  To: meta

By adding "+code" next to "mirror" at the top next to the search
box.  Instead of showing "/path/to/$FOO", showing "$FOO.git"
makes it more obvious we're talking about a git repo, here,
instead of some random directory.
---
 lib/PublicInbox/Git.pm       |  2 +-
 lib/PublicInbox/WwwStream.pm | 23 ++++++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index f680eb2f..2ae5eff9 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -427,7 +427,7 @@ sub local_nick ($) {
 	my $ret = '???';
 	# don't show full FS path, basename should be OK:
 	if ($self->{git_dir} =~ m!/([^/]+)(?:/\.git)?\z!) {
-		$ret = "/path/to/$1";
+		$ret = "$1.git";
 	}
 	wantarray ? ($ret) : $ret;
 }
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index be9e762e..4db8dc55 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -51,9 +51,10 @@ sub html_top ($) {
 	} elsif ($ctx->{qp}->{t}) {
 		$top = qq(<a\nhref="./">$top</a>);
 	}
+	my $code = $ibx->{coderepo} ? qq( / <a\nhref=#code>code</a>) : '';
 	my $links = qq(<a\nhref="$help">help</a> / ).
 			qq(<a\nhref="$color">color</a> / ).
-			qq(<a\nhref=#mirror>mirror</a> / ).
+			qq(<a\nhref=#mirror>mirror</a>$code / ).
 			qq(<a\nhref="$atom">Atom feed</a>);
 	if ($ibx->isrch) {
 		my $q_val = delete($ctx->{-q_value_html}) // '';
@@ -84,16 +85,20 @@ sub coderepos ($) {
 	my $upfx = ($ctx->{-upfx} // ''). '../';
 	my @ret;
 	for my $cr_name (@$cr) {
-		my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl") // next;
 		$ret[0] //= <<EOF;
-code repositories for the project(s) associated with this inbox:
+<a id=code>code repositories for project(s) associated with this inbox:
 EOF
-		for (@$urls) {
-			# relative or absolute URL?, prefix relative "foo.git"
-			# with appropriate number of "../"
-			my $u = m!\A(?:[a-z\+]+:)?//! ? $_ : $upfx.$_;
-			$u = ascii_html(prurl($ctx->{env}, $u));
-			$ret[0] .= qq(\n\t<a\nhref="$u">$u</a>);
+		my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl");
+		if ($urls) {
+			for (@$urls) {
+				# relative or absolute URL?, prefix relative
+				# "foo.git" with appropriate number of "../"
+				my $u = m!\A(?:[a-z\+]+:)?//! ? $_ : $upfx.$_;
+				$u = ascii_html(prurl($ctx->{env}, $u));
+				$ret[0] .= qq(\n\t<a\nhref="$u">$u</a>);
+			}
+		} else {
+			$ret[0] .= qq[\n\t$cr_name.git (no URL configured)];
 		}
 	}
 	@ret; # may be empty, this sub is called as an arg for join()

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 5/5] tests: show lsof output on deleted-file-check failures
  2021-03-17  7:02 [PATCH 0/5] www: extindex stuff Eric Wong
                   ` (3 preceding siblings ...)
  2021-03-17  7:02 ` [PATCH 4/5] www: improve visibility of coderepos Eric Wong
@ 2021-03-17  7:02 ` Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2021-03-17  7:02 UTC (permalink / raw)
  To: meta

This may help track down some occasional test failures I'm
seeing.
---
 t/httpd-corner.t | 3 ++-
 t/nntpd.t        | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/t/httpd-corner.t b/t/httpd-corner.t
index 794d8aeb..296e1dc1 100644
--- a/t/httpd-corner.t
+++ b/t/httpd-corner.t
@@ -610,7 +610,8 @@ SKIP: {
 	my $null_in = '';
 	my $rdr = { 2 => \(my $null_err), 0 => \$null_in };
 	my @lsof = xqx([$lsof, '-p', $td->{pid}], undef, $rdr);
-	is_deeply([grep(/\bdeleted\b/, @lsof)], [], 'no lingering deleted inputs');
+	my $d = [ grep(/\(deleted\)/, @lsof) ];
+	is_deeply($d, [], 'no lingering deleted inputs') or diag explain($d);
 
 	# filter out pipes inherited from the parent
 	my @this = xqx([$lsof, '-p', $$], undef, $rdr);
diff --git a/t/nntpd.t b/t/nntpd.t
index 7db371dd..ce4d7cf9 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -365,8 +365,9 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 		$lsof or skip 'lsof missing', 1;
 		($^O =~ /\A(?:linux)\z/) or
 			skip "lsof /(deleted)/ check untested on $^O", 1;
-		my @of = xqx([$lsof, '-p', $td->{pid}], undef, $noerr);
-		is(scalar(grep(/\(deleted\)/, @of)), 0, 'no deleted files');
+		my @lsof = xqx([$lsof, '-p', $td->{pid}], undef, $noerr);
+		my $d = [ grep(/\(deleted\)/, @lsof) ];
+		is_deeply($d, [], 'no deleted files') or diag explain($d);
 	};
 	SKIP: { test_watch($tmpdir, $host_port, $group) };
 	{

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-17  7:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 3/5] config: lazy-load coderepos, support extindex Eric Wong
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

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git