From: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
To: git@vger.kernel.org
Cc: Jakub Narebski <jnareb@gmail.com>, Petr Baudis <pasky@suse.cz>,
Junio C Hamano <gitster@pobox.com>,
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Subject: [PATCHv2 1/2] gitweb: fixes to gitweb feature check code
Date: Fri, 28 Nov 2008 21:39:52 +0100 [thread overview]
Message-ID: <1227904793-1821-2-git-send-email-giuseppe.bilotta@gmail.com> (raw)
In-Reply-To: <1227904793-1821-1-git-send-email-giuseppe.bilotta@gmail.com>
The gitweb_check_feature routine was being used for two different
purposes: retrieving the actual feature value (such as the list of
snapshot formats or the list of additional actions), and to check if a
feature was enabled.
For the latter use, since all features return an array, it led to either
clumsy code or subtle bugs, with disabled features appearing enabled
because (0) evaluates to 1.
We fix these bugs, and simplify the code, by separating feature (list)
value retrieval (gitweb_get_feature) from boolean feature check (i.e.
retrieving the first/only item in the feature value list). Usage of
gitweb_check_feature is replaced by gitweb_get_feature where
appropriate.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
gitweb/gitweb.perl | 26 ++++++++++++++++++++++----
1 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 933e137..128d7ad 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -190,7 +190,9 @@ our %feature = (
# if there is no 'sub' key (no feature-sub), then feature cannot be
# overriden
#
- # use gitweb_check_feature(<feature>) to check if <feature> is enabled
+ # use gitweb_get_feature(<feature>) to retrieve the <feature> value
+ # (an array) or gitweb_check_feature(<feature>) to check if <feature>
+ # is enabled
# Enable the 'blame' blob view, showing the last commit that modified
# each line in the file. This can be very CPU-intensive.
@@ -329,7 +331,8 @@ our %feature = (
'default' => [0]},
);
-sub gitweb_check_feature {
+# retrieve the value of a given feature, as an array
+sub gitweb_get_feature {
my ($name) = @_;
return unless exists $feature{$name};
my ($sub, $override, @defaults) = (
@@ -344,6 +347,21 @@ sub gitweb_check_feature {
return $sub->(@defaults);
}
+# check if a given feature is enabled or not, returning the first (and only)
+# value of the feature. Comfort code, allowing the use of
+# my $bool_feat = gitweb_check_feature('bool_feat');
+# or
+# gitweb_check_feature('bool_feat') or somecode;
+# instead of
+# my ($bool_feat) = gitweb_git_feature('bool_feat');
+# or
+# (gitweb_check_feature('bool_feat'))[0] or somecode;
+# respectively
+sub gitweb_check_feature {
+ return (gitweb_get_feature(@_))[0];
+}
+
+
sub feature_blame {
my ($val) = git_get_project_config('blame', '--bool');
@@ -767,7 +785,7 @@ our $git_dir;
$git_dir = "$projectroot/$project" if $project;
# list of supported snapshot formats
-our @snapshot_fmts = gitweb_check_feature('snapshot');
+our @snapshot_fmts = gitweb_get_feature('snapshot');
@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
# dispatch
@@ -3084,7 +3102,7 @@ sub git_print_page_nav {
$arg{'tree'}{'hash'} = $treehead if defined $treehead;
$arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
- my @actions = gitweb_check_feature('actions');
+ my @actions = gitweb_get_feature('actions');
my %repl = (
'%' => '%',
'n' => $project, # project name
--
1.5.6.5
next prev parent reply other threads:[~2008-11-28 20:40 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-28 20:39 [PATCHv2 0/2] fixes to gitweb feature check code Giuseppe Bilotta
2008-11-28 20:39 ` Giuseppe Bilotta [this message]
2008-11-28 20:39 ` [PATCHv2 2/2] gitweb: clean up git_check_feature() calls Giuseppe Bilotta
2008-11-29 11:15 ` [PATCHv2 2/2] gitweb: clean up gitweb_check_feature() calls Giuseppe Bilotta
2008-11-29 11:18 ` Jakub Narebski
2008-11-29 11:53 ` [PATCHv2ter " Giuseppe Bilotta
2008-11-29 20:39 ` Junio C Hamano
2008-11-29 21:00 ` Junio C Hamano
2008-11-29 21:12 ` [PATCH 2/3] gitweb: rename gitweb_check_feature to gitweb_get_feature Junio C Hamano
2008-11-29 21:16 ` [PATCH 3/3] gitweb: make gitweb_check_feature a boolean wrapper Junio C Hamano
2008-11-29 22:27 ` Giuseppe Bilotta
2008-11-30 0:23 ` Junio C Hamano
2008-11-30 1:31 ` Giuseppe Bilotta
2008-11-29 22:16 ` [PATCHv2ter 2/2] gitweb: clean up gitweb_check_feature() calls Giuseppe Bilotta
2008-11-29 22:26 ` Junio C Hamano
2008-11-29 22:36 ` Jakub Narebski
2008-11-29 22:38 ` Jakub Narebski
2008-11-30 0:31 ` [PATCHv2 1/2] gitweb: fixes to gitweb feature check code Jakub Narebski
2008-11-29 10:48 ` [PATCHv2 0/2] " Jakub Narebski
2008-11-29 11:13 ` Giuseppe Bilotta
[not found] <Message-ID: <cb7bb73a0811291731g7f8770f7p89e924c00d2ab004@mail.gmail.com>
2008-11-30 1:34 ` [PATCH] gitweb: " Giuseppe Bilotta
2008-12-02 1:53 ` Jakub Narebski
2008-12-02 10:43 ` [PATCHv3bis] " Giuseppe Bilotta
2008-12-03 2:18 ` Junio C Hamano
2008-12-02 21:55 ` [PATCH] " Junio C Hamano
2008-12-03 1:21 ` 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=1227904793-1821-2-git-send-email-giuseppe.bilotta@gmail.com \
--to=giuseppe.bilotta@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
--cc=pasky@suse.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).