Skip to content

Commit a781785

Browse files
jnarebgitster
authored andcommitted
gitweb: Fix support for legacy gitweb config for snapshots
Earlier commit which cleaned up snapshot support and introduced support for multiple snapshot formats changed the format of $feature{'snapshot'}{'default'} (gitweb configuration) and gitweb.snapshot configuration variable (repository configuration). It supported old gitweb.snapshot values of 'gzip', 'bzip2' and 'zip' and tried to support, but failed to do that, old values of $feature{'snapshot'}{'default'}; at least those corresponding to old gitweb.snapshot values of 'gzip', 'bzip2' and 'zip', i.e. ['x-gzip', 'gz', 'gzip'] ['x-bzip2', 'bz2', 'bzip2'] ['x-zip', 'zip', ''] This commit moves legacy configuration support out of feature_snapshot subroutine to separate filter_snapshot_fmts subroutine. The filter_snapshot_fmts is used on result on result of gitweb_check_feature('snapshot'). This way feature_snapshot deals _only_ with repository config. As a byproduct you can now use 'gzip' and 'bzip2' as aliases to 'tgz' and 'tbz2' also in $feature{'snapshot'}{'default'}, not only in gitweb.snapshot. While at it do some whitespace cleanup: use tabs for indent, but spaces for align. Noticed-by: Matt McCutchen <hashproduct@gmail.com> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Tested-by: Matt McCutchen <hashproduct@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 16a7fcf commit a781785

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

gitweb/gitweb.perl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,6 @@ sub feature_snapshot {
307307

308308
if ($val) {
309309
@fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
310-
@fmts = grep { defined } map {
311-
exists $known_snapshot_format_aliases{$_} ?
312-
$known_snapshot_format_aliases{$_} : $_ } @fmts;
313-
@fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
314310
}
315311

316312
return @fmts;
@@ -356,6 +352,18 @@ sub check_export_ok {
356352
(!$export_ok || -e "$dir/$export_ok"));
357353
}
358354

355+
# process alternate names for backward compatibility
356+
# filter out unsupported (unknown) snapshot formats
357+
sub filter_snapshot_fmts {
358+
my @fmts = @_;
359+
360+
@fmts = map {
361+
exists $known_snapshot_format_aliases{$_} ?
362+
$known_snapshot_format_aliases{$_} : $_} @fmts;
363+
@fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
364+
365+
}
366+
359367
our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
360368
do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
361369

@@ -1299,9 +1307,11 @@ sub format_diff_line {
12991307
sub format_snapshot_links {
13001308
my ($hash) = @_;
13011309
my @snapshot_fmts = gitweb_check_feature('snapshot');
1310+
@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
13021311
my $num_fmts = @snapshot_fmts;
13031312
if ($num_fmts > 1) {
13041313
# A parenthesized list of links bearing format names.
1314+
# e.g. "snapshot (_tar.gz_ _zip_)"
13051315
return "snapshot (" . join(' ', map
13061316
$cgi->a({
13071317
-href => href(
@@ -1313,8 +1323,10 @@ sub format_snapshot_links {
13131323
, @snapshot_fmts) . ")";
13141324
} elsif ($num_fmts == 1) {
13151325
# A single "snapshot" link whose tooltip bears the format name.
1326+
# i.e. "_snapshot_"
13161327
my ($fmt) = @snapshot_fmts;
1317-
return $cgi->a({
1328+
return
1329+
$cgi->a({
13181330
-href => href(
13191331
action=>"snapshot",
13201332
hash=>$hash,
@@ -4302,11 +4314,12 @@ sub git_tree {
43024314

43034315
sub git_snapshot {
43044316
my @supported_fmts = gitweb_check_feature('snapshot');
4317+
@supported_fmts = filter_snapshot_fmts(@supported_fmts);
43054318

43064319
my $format = $cgi->param('sf');
43074320
unless ($format =~ m/[a-z0-9]+/
4308-
&& exists($known_snapshot_formats{$format})
4309-
&& grep($_ eq $format, @supported_fmts)) {
4321+
&& exists($known_snapshot_formats{$format})
4322+
&& grep($_ eq $format, @supported_fmts)) {
43104323
die_error(undef, "Unsupported snapshot format");
43114324
}
43124325

0 commit comments

Comments
 (0)