This also ensures we won't waste CPU cycles on snapshots
which aren't configured if somebody attempts them by
guessing URLs.
+=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
=item publicinbox.cgitrc
A path to a L<cgitrc(5)> file. "repo.url" directives in the cgitrc
} elsif (m!\A(?:css|favicon|logo|repo\.logo)=(/.+)\z!) {
# absolute paths for static files via PublicInbox::Cgit
$self->{-cgit_static}->{$1} = 1;
} 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;
}
}
cgit_repo_merge($self, $repo->{dir}, $repo) if $repo;
sub srv {
my ($ctx, $fn) = @_;
return if $fn =~ /["\s]/s;
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/-/;
$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));
substr($fn, 0, length($pfx)) eq $pfx or return;
$ctx->{snap_pfx} = $fn;
my $v = $ctx->{snap_ver} = substr($fn, length($pfx), length($fn));
use PublicInbox::GitAsyncCat;
use PublicInbox::WwwStream;
use PublicInbox::Hval qw(ascii_html);
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 { "%($_)" }
my $EACH_REF = "git for-each-ref --sort=-creatordate --format='%(HEAD)%00".
join('%00', map { "%($_)" }
my ($cls, $pi_cfg) = @_;
my $self = bless { pi_cfg => $pi_cfg }, $cls;
prepare_coderepos($self);
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;
$self->{$_} = 10 for qw(summary_branches summary_tags);
$self->{$_} = 10 for qw(summary_log);
$self;
"%(refname:short) %(subject) (%(creatordate:short))'\n";
@r = split(/^/sm, shift(@x) // '');
$last = pop(@r) if scalar(@r) > $ctx->{wcr}->{summary_tags};
"%(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),
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;
}
print $zfh "# no tags yet...\n" if !@r;
print $zfh "...\n" if $last;
# snapshots:
if ($path_info =~ m!\A/(.+?)/snapshot/([^/]+)\z! and
($ctx->{git} = $self->{"\0$1"})) {
# snapshots:
if ($path_info =~ m!\A/(.+?)/snapshot/([^/]+)\z! and
($ctx->{git} = $self->{"\0$1"})) {
- require PublicInbox::RepoSnapshot;
return PublicInbox::RepoSnapshot::srv($ctx, $2) // r(404);
}
return PublicInbox::RepoSnapshot::srv($ctx, $2) // r(404);
}
my $cfgpath = "$tmpdir/httpd-config";
open my $cfgfh, '>', $cfgpath or die;
print $cfgfh <<EOF or die;
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}
[publicinbox "$name"]
address = $ibx->{-primary_address}
inboxdir = $ibx->{inboxdir}
$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.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 };
};
test_psgi(sub { $www->call(@_) }, $client);
my $env = { PI_CONFIG => $cfgpath, TMPDIR => $tmpdir };