From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/5] www_coderepo: wire up snapshots from summary
Date: Sat, 8 Oct 2022 08:24:45 +0000 [thread overview]
Message-ID: <20221008082448.9856-3-e@80x24.org> (raw)
In-Reply-To: <20221008082448.9856-1-e@80x24.org>
This also ensures we won't waste CPU cycles on snapshots
which aren't configured if somebody attempts them by
guessing URLs.
---
Documentation/public-inbox-config.pod | 4 ++++
lib/PublicInbox/Config.pm | 2 ++
lib/PublicInbox/RepoSnapshot.pm | 4 +++-
lib/PublicInbox/WwwCoderepo.pm | 25 +++++++++++++++++++++++--
t/solver_git.t | 6 ++++++
5 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod
index e926a27b..d175d2d7 100644
--- a/Documentation/public-inbox-config.pod
+++ b/Documentation/public-inbox-config.pod
@@ -265,6 +265,10 @@ The URL of the cgit instance associated with the coderepo.
Default: none
+=item coderepo.snapshots
+
+See C<snapshots> in L<cgitrc(5)>
+
=item publicinbox.cgitrc
A path to a L<cgitrc(5)> file. "repo.url" directives in the cgitrc
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 5cdf182e..a430cd5c 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -325,6 +325,8 @@ sub parse_cgitrc {
} elsif (m!\A(?:css|favicon|logo|repo\.logo)=(/.+)\z!) {
# absolute paths for static files via PublicInbox::Cgit
$self->{-cgit_static}->{$1} = 1;
+ } elsif (s!\Asnapshots=\s*!!) {
+ $self->{'coderepo.snapshots'} = $_;
}
}
cgit_repo_merge($self, $repo->{dir}, $repo) if $repo;
diff --git a/lib/PublicInbox/RepoSnapshot.pm b/lib/PublicInbox/RepoSnapshot.pm
index 460340e6..826392a8 100644
--- a/lib/PublicInbox/RepoSnapshot.pm
+++ b/lib/PublicInbox/RepoSnapshot.pm
@@ -72,10 +72,12 @@ sub ver_check { # git->check_async callback
sub srv {
my ($ctx, $fn) = @_;
return if $fn =~ /["\s]/s;
- $fn =~ s/\.($SUFFIX)\z//o or return;
+ my $fmt = $ctx->{wcr}->{snapshots}; # TODO per-repo snapshots
+ $fn =~ s/\.($SUFFIX)\z//o and $fmt->{$1} or return;
$ctx->{snap_fmt} = $1;
my $pfx = $ctx->{git}->local_nick // return;
$pfx =~ s/(?:\.git)?\z/-/;
+ ($pfx) = ($pfx =~ m!([^/]+)\z!);
substr($fn, 0, length($pfx)) eq $pfx or return;
$ctx->{snap_pfx} = $fn;
my $v = $ctx->{snap_ver} = substr($fn, length($pfx), length($fn));
diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm
index d491bba2..01ed562b 100644
--- a/lib/PublicInbox/WwwCoderepo.pm
+++ b/lib/PublicInbox/WwwCoderepo.pm
@@ -12,6 +12,7 @@ use PublicInbox::Git;
use PublicInbox::GitAsyncCat;
use PublicInbox::WwwStream;
use PublicInbox::Hval qw(ascii_html);
+use PublicInbox::RepoSnapshot;
my $EACH_REF = "git for-each-ref --sort=-creatordate --format='%(HEAD)%00".
join('%00', map { "%($_)" }
@@ -40,6 +41,11 @@ sub new {
my ($cls, $pi_cfg) = @_;
my $self = bless { pi_cfg => $pi_cfg }, $cls;
prepare_coderepos($self);
+ $self->{snapshots} = do {
+ my $s = $pi_cfg->{'coderepo.snapshots'} // '';
+ $s eq 'all' ? \%PublicInbox::RepoSnapshot::FMT_TYPES :
+ +{ map { $_ => 1 } split(/\s+/, $s) };
+ };
$self->{$_} = 10 for qw(summary_branches summary_tags);
$self->{$_} = 10 for qw(summary_log);
$self;
@@ -111,13 +117,28 @@ EOM
"%(refname:short) %(subject) (%(creatordate:short))'\n";
@r = split(/^/sm, shift(@x) // '');
$last = pop(@r) if scalar(@r) > $ctx->{wcr}->{summary_tags};
+ my @s = sort keys %{$ctx->{wcr}->{snapshots}};
+ my $n;
+ if (@s) {
+ $n = $ctx->{git}->local_nick // die "BUG: $ctx->{git_dir} nick";
+ $n =~ s/\.git\z/-/;
+ ($n) = ($n =~ m!([^/]+)\z!);
+ $n = ascii_html($n);
+ }
for (@r) {
my (undef, $oid, $ref, $s, $cd) = split(/\0/);
utf8::decode($_) for ($ref, $s);
chomp $cd;
my $align = length($ref) < 12 ? ' ' x (12 - length($ref)) : '';
print $zfh "<a\nhref=./$oid/s/>", ascii_html($ref),
- "</a>$align ", ascii_html($s), " ($cd)\n";
+ "</a>$align ", ascii_html($s), " ($cd)";
+ if (@s) {
+ my $v = $ref;
+ $v =~ s/\A[vV]//;
+ print $zfh "\t", join(' ', map {
+ qq{<a href="snapshot/$n$v.$_">$_</a>} } @s);
+ }
+ print $zfh "\n";
}
print $zfh "# no tags yet...\n" if !@r;
print $zfh "...\n" if $last;
@@ -186,7 +207,7 @@ sub srv { # endpoint called by PublicInbox::WWW
# snapshots:
if ($path_info =~ m!\A/(.+?)/snapshot/([^/]+)\z! and
($ctx->{git} = $self->{"\0$1"})) {
- require PublicInbox::RepoSnapshot;
+ $ctx->{wcr} = $self;
return PublicInbox::RepoSnapshot::srv($ctx, $2) // r(404);
}
diff --git a/t/solver_git.t b/t/solver_git.t
index 71b9554a..d8942747 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -247,6 +247,8 @@ SKIP: {
my $cfgpath = "$tmpdir/httpd-config";
open my $cfgfh, '>', $cfgpath or die;
print $cfgfh <<EOF or die;
+[coderepo]
+ snapshots = tar.gz
[publicinbox "$name"]
address = $ibx->{-primary_address}
inboxdir = $ibx->{inboxdir}
@@ -351,6 +353,10 @@ EOF
$fn = 'public-inbox-1.0.2.tar.gz';
$res = $cb->(GET("/public-inbox/snapshot/$fn"));
is($res->code, 404, '404 on non-existent tag');
+
+ $fn = 'public-inbox-1.0.0.tar.bz2';
+ $res = $cb->(GET("/public-inbox/snapshot/$fn"));
+ is($res->code, 404, '404 on unconfigured snapshot format');
};
test_psgi(sub { $www->call(@_) }, $client);
my $env = { PI_CONFIG => $cfgpath, TMPDIR => $tmpdir };
next prev parent reply other threads:[~2022-10-08 8:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-08 8:24 [PATCH 0/5] www: some coderepo stuff Eric Wong
2022-10-08 8:24 ` [PATCH 1/5] config: remove {-cgitrc_unparsed} field Eric Wong
2022-10-08 8:24 ` Eric Wong [this message]
2022-10-08 8:24 ` [PATCH 3/5] www_coderepo: update blurb on the goal/purpose of this Eric Wong
2022-10-08 8:24 ` [PATCH 4/5] www: cgit: fix fallback to WwwCoderepo on array responses Eric Wong
2022-10-08 8:24 ` [PATCH 5/5] www_coderepo: allow searching one extindex|inbox 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=20221008082448.9856-3-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).