Skip to content

Commit 5e16684

Browse files
Oblomovgitster
authored andcommitted
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>
1 parent 8db49a7 commit 5e16684

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

gitweb/gitweb.perl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@ sub evaluate_path_info {
721721
our $git_dir;
722722
$git_dir = "$projectroot/$project" if $project;
723723

724+
# list of supported snapshot formats
725+
our @snapshot_fmts = gitweb_check_feature('snapshot');
726+
@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
727+
724728
# dispatch
725729
if (!defined $action) {
726730
if (defined $hash) {
@@ -1647,8 +1651,6 @@ sub format_diff_line {
16471651
# linked. Pass the hash of the tree/commit to snapshot.
16481652
sub format_snapshot_links {
16491653
my ($hash) = @_;
1650-
my @snapshot_fmts = gitweb_check_feature('snapshot');
1651-
@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
16521654
my $num_fmts = @snapshot_fmts;
16531655
if ($num_fmts > 1) {
16541656
# A parenthesized list of links bearing format names.
@@ -4846,20 +4848,17 @@ sub git_tree {
48464848
}
48474849

48484850
sub git_snapshot {
4849-
my @supported_fmts = gitweb_check_feature('snapshot');
4850-
@supported_fmts = filter_snapshot_fmts(@supported_fmts);
4851-
48524851
my $format = $input_params{'snapshot_format'};
4853-
if (!@supported_fmts) {
4852+
if (!@snapshot_fmts) {
48544853
die_error(403, "Snapshots not allowed");
48554854
}
48564855
# default to first supported snapshot format
4857-
$format ||= $supported_fmts[0];
4856+
$format ||= $snapshot_fmts[0];
48584857
if ($format !~ m/^[a-z0-9]+$/) {
48594858
die_error(400, "Invalid snapshot format parameter");
48604859
} elsif (!exists($known_snapshot_formats{$format})) {
48614860
die_error(400, "Unknown snapshot format");
4862-
} elsif (!grep($_ eq $format, @supported_fmts)) {
4861+
} elsif (!grep($_ eq $format, @snapshot_fmts)) {
48634862
die_error(403, "Unsupported snapshot format");
48644863
}
48654864

0 commit comments

Comments
 (0)