gitweb: make the supported snapshot formats array global
The array of supported snapshot format is used and defined (with two different names) in two routines, one of which (format_snapshot_links) is often called multiple times per page. Simplify code and speed up page generation by making the array global. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Giuseppe Bilotta committed
Nov 2, 2008 at 10:21 UTC
5e166843f502536df7e940486721057acf37ec23
1 file changed
+7
-8
gitweb/gitweb.perl
+7
-8
@@ -721,6 +721,10 @@ if (defined $searchtext) {
721
our $git_dir;
722
$git_dir = "$projectroot/$project" if $project;
723
724
+# list of supported snapshot formats
725
+our @snapshot_fmts = gitweb_check_feature('snapshot');
726
+@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
727
+
728
# dispatch
729
if (!defined $action) {
730
if (defined $hash) {
@@ -1647,8 +1651,6 @@ sub format_diff_line {
1651
# linked. Pass the hash of the tree/commit to snapshot.
1652
sub format_snapshot_links {
1653
my ($hash) = @_;
1650
- my @snapshot_fmts = gitweb_check_feature('snapshot');
1651
- @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
1654
my $num_fmts = @snapshot_fmts;
1655
if ($num_fmts > 1) {
1656
# A parenthesized list of links bearing format names.
@@ -4846,20 +4848,17 @@ sub git_tree {
4848
}
4849
4850
sub git_snapshot {
4849
- my @supported_fmts = gitweb_check_feature('snapshot');
4850
- @supported_fmts = filter_snapshot_fmts(@supported_fmts);
4851
-
4851
my $format = $input_params{'snapshot_format'};
4853
- if (!@supported_fmts) {
4852
+ if (!@snapshot_fmts) {
4853
die_error(403, "Snapshots not allowed");
4854
}
4855
# default to first supported snapshot format
4857
- $format ||= $supported_fmts[0];
4856
+ $format ||= $snapshot_fmts[0];
4857
if ($format !~ m/^[a-z0-9]+$/) {
4858
die_error(400, "Invalid snapshot format parameter");
4859
} elsif (!exists($known_snapshot_formats{$format})) {
4860
die_error(400, "Unknown snapshot format");
4862
- } elsif (!grep($_ eq $format, @supported_fmts)) {
4861
+ } elsif (!grep($_ eq $format, @snapshot_fmts)) {
4862
die_error(403, "Unsupported snapshot format");
4863
}
4864