From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 14/14] www: start working on a repo listing
Date: Tue, 28 Nov 2023 14:56:27 +0000 [thread overview]
Message-ID: <20231128145628.1455176-15-e@80x24.org> (raw)
In-Reply-To: <20231128145628.1455176-1-e@80x24.org>
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 <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+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} // '';
+ "<html><head><title>$title</title>" .
+ $ctx->{www}->style($upfx) . '</head><body>';
+}
+
+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 "<pre>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{ <a\nhref="$u">$nick</a>}
+ }
+ }
+ $ctx->html_done('</pre>');
+}
+
+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);
next prev parent reply other threads:[~2023-11-28 14:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 14:56 [PATCH 00/14] IT'S ALIVE! www loads cindex join data Eric Wong
2023-11-28 14:56 ` [PATCH 01/14] test_common: create_*: detect changes all parameters Eric Wong
2023-11-28 14:56 ` [PATCH 02/14] t/cindex*: require SCM_RIGHTS for these tests Eric Wong
2024-01-29 21:23 ` [PATCH 0/2] pure Perl sendmsg/recvmsg on *BSD Eric Wong
2024-01-29 21:23 ` [PATCH 1/2] syscall: update formatting to match our codebase Eric Wong
2024-01-29 21:23 ` [PATCH 2/2] syscall: use pure Perl sendmsg/recvmsg on *BSD Eric Wong
2024-04-06 0:43 ` Gaelan Steele
2024-04-08 9:48 ` [RFT] syscall: set default constants for Inline::C platforms Eric Wong
2024-04-08 12:12 ` Gaelan Steele
2024-04-08 20:11 ` Eric Wong
2023-11-28 14:56 ` [PATCH 03/14] codesearch: eliminate redundant substitutions Eric Wong
2023-11-28 14:56 ` [PATCH 04/14] solver: schedule cleanup after synchronous git->check Eric Wong
2023-11-28 14:56 ` [PATCH 05/14] xap_helper.h: move cindex endpoints to separate file Eric Wong
2023-11-28 14:56 ` [PATCH 06/14] xap_helper: implement mset endpoint for WWW, IMAP, etc Eric Wong
2023-11-28 14:56 ` [PATCH 07/14] hval: use File::Spec to make relative paths for href Eric Wong
2023-11-28 14:56 ` [PATCH 08/14] www: load and use cindex join data Eric Wong
2023-11-28 14:56 ` [PATCH 09/14] git: speed up ->git_path for non-worktrees Eric Wong
2023-11-28 14:56 ` [PATCH 10/14] cindex: require `-g GIT_DIR' or `-r PROJECT_ROOT' Eric Wong
2023-11-28 14:56 ` [PATCH 11/14] git: speed up Git->new by 5% or so Eric Wong
2023-11-28 14:56 ` [PATCH 12/14] admin: resolve_git_dir respects symlinks Eric Wong
2023-11-28 14:56 ` [PATCH 13/14] cindex: extra quit checks Eric Wong
2023-11-28 14:56 ` Eric Wong [this message]
2023-11-28 17:55 ` [PATCH 15/14] www: load cindex join data for ->ALL, too 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=20231128145628.1455176-15-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.
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).