From: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
To: git@vger.kernel.org, jnareb@gmail.com, chriscool@tuxfamily.org,
pasky@ucw.cz
Cc: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
Subject: [RFC/PATCH 1/4] gitweb: Move subroutines to Gitweb::Config module
Date: Tue, 8 Jun 2010 02:20:41 +0530 [thread overview]
Message-ID: <1275943844-24991-1-git-send-email-pavan.sss1991@gmail.com> (raw)
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 <pavan.sss1991@gmail.com>
---
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
next reply other threads:[~2010-06-07 20:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-07 20:50 Pavan Kumar Sunkara [this message]
2010-06-07 20:50 ` [RFC/PATCH 2/4] gitweb: Create Gitweb::HTML::Link module Pavan Kumar Sunkara
2010-06-07 20:50 ` [RFC/PATCH 3/4] gitweb: Create Gitweb::HTML module Pavan Kumar Sunkara
2010-06-07 20:50 ` [RFC/PATCH 4/4] gitweb: Create Gitweb::HTML::String module Pavan Kumar Sunkara
2010-06-07 20:58 ` Pavan Kumar Sunkara
2010-06-08 12:46 ` [RFC/PATCH 1/4] gitweb: Move subroutines to Gitweb::Config module Jakub Narebski
2010-06-08 13:50 ` Ævar Arnfjörð Bjarmason
2010-06-12 1:01 ` Jakub Narebski
2010-06-12 1:22 ` Ævar Arnfjörð Bjarmason
2010-06-12 1:41 ` Jakub Narebski
2010-06-08 14:13 ` Petr Baudis
2010-06-08 19:22 ` Pavan Kumar Sunkara
2010-06-08 19:55 ` Petr Baudis
2010-06-08 20:24 ` Pavan Kumar Sunkara
2010-06-08 20:50 ` Petr Baudis
2010-06-08 23:38 ` Jakub Narebski
2010-06-09 13:13 ` Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1275943844-24991-1-git-send-email-pavan.sss1991@gmail.com \
--to=pavan.sss1991@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
--cc=pasky@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).