[RFC/PATCH 1/4] gitweb: Move subroutines to Gitweb::Config module
From: Pavan Kumar Sunkara <hidden>
Date: 2016-06-15 22:48:55
Subsystem:
the rest · Maintainer:
Linus Torvalds
Subroutines moved: gitweb_get_feature gitweb_check_feature filter_snapshot_fmts configure_gitweb_features Subroutines yet to move: (Contains not yet packaged subs & vars) feature_bool feature_avatar feature_snapshot feature_pathces Signed-off-by: Pavan Kumar Sunkara <redacted> --- gitweb/gitweb.perl | 67 -------------------------------------- gitweb/lib/Gitweb/Config.pm | 74 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 69 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 9b2fe09..3931064 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl@@ -67,40 +67,6 @@ $strict_export = "++GITWEB_STRICT_EXPORT++"; $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++"; -sub gitweb_get_feature { - my ($name) = @_; - return unless exists $feature{$name}; - my ($sub, $override, @defaults) = ( - $feature{$name}{'sub'}, - $feature{$name}{'override'}, - @{$feature{$name}{'default'}}); - # project specific override is possible only if we have project - if (!$override || !defined $git_dir) { - return @defaults; - } - if (!defined $sub) { - warn "feature $name is not overridable"; - return @defaults; - } - return $sub->(@defaults); -} - -# A wrapper to check if a given feature is enabled. -# With this, you can say -# -# my $bool_feat = gitweb_check_feature('bool_feat'); -# gitweb_check_feature('bool_feat') or somecode; -# -# instead of -# -# my ($bool_feat) = gitweb_get_feature('bool_feat'); -# (gitweb_get_feature('bool_feat'))[0] or somecode; -# -sub gitweb_check_feature { - return (gitweb_get_feature(@_))[0]; -} - - sub feature_bool { my $key = shift; my ($val) = git_get_project_config($key, '--bool');
@@ -159,19 +125,6 @@ sub check_export_ok { (!$export_auth_hook || $export_auth_hook->($dir))); } -# process alternate names for backward compatibility -# filter out unsupported (unknown) snapshot formats -sub filter_snapshot_fmts { - my @fmts = @_; - - @fmts = map { - exists $known_snapshot_format_aliases{$_} ? - $known_snapshot_format_aliases{$_} : $_} @fmts; - @fmts = grep { - exists $known_snapshot_formats{$_} && - !$known_snapshot_formats{$_}{'disabled'}} @fmts; -} - # Get loadavg of system, to compare against $maxload. # Currently it requires '/proc/loadavg' present to get loadavg; # if it is not present it returns 0, which means no load checking.
@@ -486,26 +439,6 @@ sub evaluate_git_dir { $git_dir = "$projectroot/$project" if $project; } -our (@snapshot_fmts, $git_avatar); -sub configure_gitweb_features { - # list of supported snapshot formats - our @snapshot_fmts = gitweb_get_feature('snapshot'); - @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); - - # check that the avatar feature is set to a known provider name, - # and for each provider check if the dependencies are satisfied. - # if the provider name is invalid or the dependencies are not met, - # reset $git_avatar to the empty string. - our ($git_avatar) = gitweb_get_feature('avatar'); - if ($git_avatar eq 'gravatar') { - $git_avatar = '' unless (eval { require Digest::MD5; 1; }); - } elsif ($git_avatar eq 'picon') { - # no dependencies - } else { - $git_avatar = ''; - } -} - # custom error handler: 'die <message>' is Internal Server Error sub handle_errors_html { my $msg = shift; # it is already HTML escaped
diff --git a/gitweb/lib/Gitweb/Config.pm b/gitweb/lib/Gitweb/Config.pm
index fdab9f7..3810fda 100644
--- a/gitweb/lib/Gitweb/Config.pm
+++ b/gitweb/lib/Gitweb/Config.pm@@ -10,13 +10,16 @@ use strict; use warnings; use Exporter qw(import); -our @EXPORT = qw(evaluate_gitweb_config $version $projectroot $project_maxdepth $mimetypes_file +our @EXPORT = qw(evaluate_gitweb_config gitweb_check_feature gitweb_get_feature configure_gitweb_features + filter_snapshot_fmts $version $projectroot $project_maxdepth $mimetypes_file $git_avatar $projects_list @git_base_url_list $export_ok $strict_export $home_link_str $site_name $site_header $site_footer $home_text @stylesheets $stylesheet $logo $favicon $javascript $GITWEB_CONFIG $GITWEB_CONFIG_SYSTEM $logo_url $logo_label $export_auth_hook $projects_list_description_width $default_projects_order $default_blob_plain_mimetype $default_text_plain_charset $fallback_encoding @diff_opts $prevent_xss $maxload - %avatar_size %known_snapshot_formats %known_snapshot_format_aliases %feature); + %avatar_size %known_snapshot_formats %feature @snapshot_fmts); + +use Gitweb::Git qw($git_dir); # The following variables are affected by build-time configuration # and hence their initialisation is put in gitweb.perl script
@@ -425,4 +428,71 @@ sub evaluate_gitweb_config { } } + +sub gitweb_get_feature { + my ($name) = @_; + return unless exists $feature{$name}; + my ($sub, $override, @defaults) = ( + $feature{$name}{'sub'}, + $feature{$name}{'override'}, + @{$feature{$name}{'default'}}); + # project specific override is possible only if we have project + if (!$override || !defined $git_dir) { + return @defaults; + } + if (!defined $sub) { + warn "feature $name is not overridable"; + return @defaults; + } + return $sub->(@defaults); +} + +# A wrapper to check if a given feature is enabled. +# With this, you can say +# +# my $bool_feat = gitweb_check_feature('bool_feat'); +# gitweb_check_feature('bool_feat') or somecode; +# +# instead of +# +# my ($bool_feat) = gitweb_get_feature('bool_feat'); +# (gitweb_get_feature('bool_feat'))[0] or somecode; +# +sub gitweb_check_feature { + return (gitweb_get_feature(@_))[0]; +} + +# process alternate names for backward compatibility +# filter out unsupported (unknown) snapshot formats +sub filter_snapshot_fmts { + my @fmts = @_; + + @fmts = map { + exists $known_snapshot_format_aliases{$_} ? + $known_snapshot_format_aliases{$_} : $_} @fmts; + @fmts = grep { + exists $known_snapshot_formats{$_} && + !$known_snapshot_formats{$_}{'disabled'}} @fmts; +} + +our (@snapshot_fmts, $git_avatar); +sub configure_gitweb_features { + # list of supported snapshot formats + our @snapshot_fmts = gitweb_get_feature('snapshot'); + @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); + + # check that the avatar feature is set to a known provider name, + # and for each provider check if the dependencies are satisfied. + # if the provider name is invalid or the dependencies are not met, + # reset $git_avatar to the empty string. + our ($git_avatar) = gitweb_get_feature('avatar'); + if ($git_avatar eq 'gravatar') { + $git_avatar = '' unless (eval { require Digest::MD5; 1; }); + } elsif ($git_avatar eq 'picon') { + # no dependencies + } else { + $git_avatar = ''; + } +} + 1;
--
1.7.1.454.ga8c50c