From a8e3c2ad544f9f78ebbe91bfe0dece0e2d385322 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 28 Nov 2023 14:56:27 +0000 Subject: www: start working on a repo listing The HTML is still extremely rough, but links seem to be mostly working... --- MANIFEST | 1 + lib/PublicInbox/CodeSearch.pm | 8 ++++++++ lib/PublicInbox/RepoList.pm | 39 +++++++++++++++++++++++++++++++++++++++ lib/PublicInbox/WwwCoderepo.pm | 3 +++ lib/PublicInbox/WwwStream.pm | 11 ++++++----- lib/PublicInbox/WwwText.pm | 10 ++++------ 6 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 lib/PublicInbox/RepoList.pm diff --git a/MANIFEST b/MANIFEST index 7b6178f9..e22674b7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -323,6 +323,7 @@ lib/PublicInbox/PktOp.pm lib/PublicInbox/Qspawn.pm lib/PublicInbox/Reply.pm lib/PublicInbox/RepoAtom.pm +lib/PublicInbox/RepoList.pm lib/PublicInbox/RepoSnapshot.pm lib/PublicInbox/RepoTree.pm lib/PublicInbox/SHA.pm diff --git a/lib/PublicInbox/CodeSearch.pm b/lib/PublicInbox/CodeSearch.pm index 7d7f6df6..7c0dd063 100644 --- a/lib/PublicInbox/CodeSearch.pm +++ b/lib/PublicInbox/CodeSearch.pm @@ -341,4 +341,12 @@ EOM } } +sub repos_sorted { + my $pi_cfg = shift; + my @recs = map { [ 0, $_ ] } @_; # PublicInbox::Git objects + my @todo = @recs; + $pi_cfg->each_cindex(\&load_commit_times, \@todo); + @recs = sort { $b->[0] <=> $a->[0] } @recs; +} + 1; diff --git a/lib/PublicInbox/RepoList.pm b/lib/PublicInbox/RepoList.pm new file mode 100644 index 00000000..4b313ed6 --- /dev/null +++ b/lib/PublicInbox/RepoList.pm @@ -0,0 +1,39 @@ +# Copyright (C) all contributors +# License: AGPL-3.0+ +package PublicInbox::RepoList; +use v5.12; +use parent qw(PublicInbox::WwwStream); +use PublicInbox::Hval qw(ascii_html prurl fmt_ts); +require PublicInbox::CodeSearch; + +sub html_top_fallback { # WwwStream->html_repo_top + my ($ctx) = @_; + my $title = delete($ctx->{-title_html}) // + ascii_html("$ctx->{env}->{PATH_INFO}*"); + my $upfx = $ctx->{-upfx} // ''; + "$title" . + $ctx->{www}->style($upfx) . ''; +} + +sub html ($$$) { + my ($wcr, $ctx, $pfx) = @_; + my $cr = $wcr->{pi_cfg}->{-coderepos}; + my @nicks = grep(m!\A\Q$pfx\E/!, keys %$cr) or return; # 404 + __PACKAGE__->html_init($ctx); + my $zfh = $ctx->zfh; + print $zfh "
matching coderepos\n";
+	my @recs = PublicInbox::CodeSearch::repos_sorted($wcr->{pi_cfg},
+							@$cr{@nicks});
+	my $env = $ctx->{env};
+	for (@recs) {
+		my ($t, $git) = @$_;
+		my $nick = ascii_html("$git->{nick}");
+		for my $u ($git->pub_urls($env)) {
+			$u = prurl($env, $u);
+			print $zfh "\n".fmt_ts($t).qq{ $nick}
+		}
+	}
+	$ctx->html_done('
'); +} + +1; diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm index 8ab4911f..d1354af5 100644 --- a/lib/PublicInbox/WwwCoderepo.pm +++ b/lib/PublicInbox/WwwCoderepo.pm @@ -19,6 +19,7 @@ use PublicInbox::ViewDiff qw(uri_escape_path); use PublicInbox::RepoSnapshot; use PublicInbox::RepoAtom; use PublicInbox::RepoTree; +use PublicInbox::RepoList; use PublicInbox::OnDestroy; use URI::Escape qw(uri_escape_utf8); use File::Spec; @@ -354,6 +355,8 @@ sub srv { # endpoint called by PublicInbox::WWW } elsif ($path_info =~ m!\A/(.+?)/(refs/(?:heads|tags))/\z! and ($ctx->{git} = $pi_cfg->get_coderepo($1))) { refs_foo($self, $ctx, $2); + } elsif ($path_info =~ m!\A/(.+?)/\z!) { + PublicInbox::RepoList::html($self, $ctx, $1) // r(404); } elsif ($path_info =~ m!\A/(.+?)\z! and ($git = $pi_cfg->get_coderepo($1))) { my $qs = $ctx->{env}->{QUERY_STRING}; diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm index 3a1d6edf..8d32074f 100644 --- a/lib/PublicInbox/WwwStream.pm +++ b/lib/PublicInbox/WwwStream.pm @@ -17,8 +17,9 @@ http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inb https://public-inbox.org/public-inbox.git) ]; sub base_url ($) { - my $ctx = shift; - my $base_url = ($ctx->{ibx} // $ctx->{git})->base_url($ctx->{env}); + my ($ctx) = @_; + my $thing = $ctx->{ibx} // $ctx->{git} // return; + my $base_url = $thing->base_url($ctx->{env}); chop $base_url; # no trailing slash for clone $base_url; } @@ -40,7 +41,7 @@ sub async_eml { # for async_blob_cb sub html_repo_top ($) { my ($ctx) = @_; - my $git = $ctx->{git}; + my $git = $ctx->{git} // return $ctx->html_top_fallback; my $desc = ascii_html($git->description); my $title = delete($ctx->{-title_html}) // $desc; my $upfx = $ctx->{-upfx} // ''; @@ -265,11 +266,11 @@ sub aresponse { } sub html_init { - my ($ctx) = @_; + my $ctx = $_[-1]; $ctx->{base_url} = base_url($ctx); my $h = $ctx->{-res_hdr} = ['Content-Type', 'text/html; charset=UTF-8']; $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($h, $ctx->{env}); - bless $ctx, __PACKAGE__; + bless $ctx, @_ > 1 ? $_[0] : __PACKAGE__; print { $ctx->zfh } html_top($ctx); } diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm index 4b4b2e4c..5e23005e 100644 --- a/lib/PublicInbox/WwwText.pm +++ b/lib/PublicInbox/WwwText.pm @@ -252,19 +252,17 @@ sub coderepos_raw ($$) { my $cr = $cfg->repo_objs($ctx->{ibx}) or return (); my $buf = 'Code repositories for project(s) associated with this '. $ctx->{ibx}->thing_type . ":\n"; - my @recs = map { [ 0, $_ ] } @$cr; - my @todo = @recs; - $cfg->each_cindex('load_commit_times', \@todo); - @recs = sort { $b->[0] <=> $a->[0] } @recs; + my @recs = PublicInbox::CodeSearch::repos_sorted($cfg, @$cr); my $cr_score = $ctx->{ibx}->{-cr_score}; + my $env = $ctx->{env}; for (@recs) { my ($t, $git) = @$_; - for ($git->pub_urls($ctx->{env})) { + for ($git->pub_urls($env)) { my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ : $top_url.$_; my $nr = $cr_score->{$git->{nick}}; $buf .= "\n"; $buf .= $nr ? sprintf('% 9u', $nr) : (' 'x9); - $buf .= ' '.fmt_ts($t).' '.prurl($ctx->{env}, $u); + $buf .= ' '.fmt_ts($t).' '.prurl($env, $u); } } ($buf); -- cgit v1.2.3-24-ge0c7