git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH 1/4] gitweb: Move subroutines to Gitweb::Config module

From
Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
Date
Jun 7, 2010, 20:50 UTC
Message-ID
<1275943844-24991-1-git-send-email-pavan.sss1991@gmail.com>
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: Pavan Kumar Sunkara
Message 1 of 17 in “gitweb: Move subroutines to Gitweb::Config module”
  1. 1/4 gitweb: Move subroutines to Gitweb::Config modulePavan Kumar Sunkara, Jun 7, 2010
  2. 2/4 gitweb: Create Gitweb::HTML::Link modulePavan Kumar Sunkara, Jun 7, 2010
  3. 3/4 gitweb: Create Gitweb::HTML modulePavan Kumar Sunkara, Jun 7, 2010
  4. 4/4 gitweb: Create Gitweb::HTML::String modulePavan Kumar Sunkara, Jun 7, 2010
  5. Pavan Kumar SunkaraJun 7, 2010
  6. Jakub NarebskiJun 8, 2010
  7. Ævar Arnfjörð BjarmasonJun 8, 2010
  8. Jakub NarebskiJun 12, 2010
  9. Ævar Arnfjörð BjarmasonJun 12, 2010
  10. Jakub NarebskiJun 12, 2010
  11. Petr BaudisJun 8, 2010
  12. Pavan Kumar SunkaraJun 8, 2010
  13. Petr BaudisJun 8, 2010
  14. Pavan Kumar SunkaraJun 8, 2010
  15. Petr BaudisJun 8, 2010
  16. Jakub NarebskiJun 8, 2010
  17. Jakub NarebskiJun 9, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.