@matheusbsbs / matheus-bagliano / commits / a781785d8f
Fork 0

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>

Jakub Narebski committed Jul 22, 2007 at 23:41 UTC a781785d8f1eb7adf05a24b121104716a086a67a
1 file changed +20 -7
gitweb/gitweb.perl
+20 -7
@@ -307,10 +307,6 @@ sub feature_snapshot {
307
308 if ($val) {
309 @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);
310 }
311
312 return @fmts;
@@ -356,6 +352,18 @@ sub check_export_ok {
352 (!$export_ok || -e "$dir/$export_ok"));
353 }
354
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 +
367 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
368 do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
369
@@ -1299,9 +1307,11 @@ sub format_diff_line {
1307 sub format_snapshot_links {
1308 my ($hash) = @_;
1309 my @snapshot_fmts = gitweb_check_feature('snapshot');
1310 + @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
1311 my $num_fmts = @snapshot_fmts;
1312 if ($num_fmts > 1) {
1313 # A parenthesized list of links bearing format names.
1314 + # e.g. "snapshot (_tar.gz_ _zip_)"
1315 return "snapshot (" . join(' ', map
1316 $cgi->a({
1317 -href => href(
@@ -1313,8 +1323,10 @@ sub format_snapshot_links {
1323 , @snapshot_fmts) . ")";
1324 } elsif ($num_fmts == 1) {
1325 # A single "snapshot" link whose tooltip bears the format name.
1326 + # i.e. "_snapshot_"
1327 my ($fmt) = @snapshot_fmts;
1317 - return $cgi->a({
1328 + return
1329 + $cgi->a({
1330 -href => href(
1331 action=>"snapshot",
1332 hash=>$hash,
@@ -4302,11 +4314,12 @@ sub git_tree {
4314
4315 sub git_snapshot {
4316 my @supported_fmts = gitweb_check_feature('snapshot');
4317 + @supported_fmts = filter_snapshot_fmts(@supported_fmts);
4318
4319 my $format = $cgi->param('sf');
4320 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)) {
4323 die_error(undef, "Unsupported snapshot format");
4324 }
4325