Skip to content

Commit dcbe0bd

Browse files
committed
Merge branch 'gb/gitweb-feature'
* gb/gitweb-feature: gitweb: make gitweb_check_feature a boolean wrapper gitweb: rename gitweb_check_feature to gitweb_get_feature gitweb: fix 'ctags' feature check and others
2 parents ed56049 + 25b2790 commit dcbe0bd

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

gitweb/gitweb.perl

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ BEGIN
329329
'default' => [0]},
330330
);
331331

332-
sub gitweb_check_feature {
332+
sub gitweb_get_feature {
333333
my ($name) = @_;
334334
return unless exists $feature{$name};
335335
my ($sub, $override, @defaults) = (
@@ -344,6 +344,22 @@ sub gitweb_check_feature {
344344
return $sub->(@defaults);
345345
}
346346

347+
# A wrapper to check if a given feature is enabled.
348+
# With this, you can say
349+
#
350+
# my $bool_feat = gitweb_check_feature('bool_feat');
351+
# gitweb_check_feature('bool_feat') or somecode;
352+
#
353+
# instead of
354+
#
355+
# my ($bool_feat) = gitweb_get_feature('bool_feat');
356+
# (gitweb_get_feature('bool_feat'))[0] or somecode;
357+
#
358+
sub gitweb_check_feature {
359+
return (gitweb_get_feature(@_))[0];
360+
}
361+
362+
347363
sub feature_blame {
348364
my ($val) = git_get_project_config('blame', '--bool');
349365

@@ -767,7 +783,7 @@ sub evaluate_path_info {
767783
$git_dir = "$projectroot/$project" if $project;
768784

769785
# list of supported snapshot formats
770-
our @snapshot_fmts = gitweb_check_feature('snapshot');
786+
our @snapshot_fmts = gitweb_get_feature('snapshot');
771787
@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
772788

773789
# dispatch
@@ -810,7 +826,7 @@ (%)
810826
}
811827
}
812828

813-
my ($use_pathinfo) = gitweb_check_feature('pathinfo');
829+
my $use_pathinfo = gitweb_check_feature('pathinfo');
814830
if ($use_pathinfo) {
815831
# try to put as many parameters as possible in PATH_INFO:
816832
# - project name
@@ -2101,7 +2117,7 @@ sub git_get_projects_list {
21012117
$filter ||= '';
21022118
$filter =~ s/\.git$//;
21032119

2104-
my ($check_forks) = gitweb_check_feature('forks');
2120+
my $check_forks = gitweb_check_feature('forks');
21052121

21062122
if (-d $projects_list) {
21072123
# search in directory
@@ -2947,7 +2963,7 @@ sub git_header_html {
29472963
}
29482964
print "</div>\n";
29492965

2950-
my ($have_search) = gitweb_check_feature('search');
2966+
my $have_search = gitweb_check_feature('search');
29512967
if (defined $project && $have_search) {
29522968
if (!defined $searchtext) {
29532969
$searchtext = "";
@@ -2961,7 +2977,7 @@ sub git_header_html {
29612977
$search_hash = "HEAD";
29622978
}
29632979
my $action = $my_uri;
2964-
my ($use_pathinfo) = gitweb_check_feature('pathinfo');
2980+
my $use_pathinfo = gitweb_check_feature('pathinfo');
29652981
if ($use_pathinfo) {
29662982
$action .= "/".esc_url($project);
29672983
}
@@ -3084,7 +3100,7 @@ sub git_print_page_nav {
30843100
$arg{'tree'}{'hash'} = $treehead if defined $treehead;
30853101
$arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
30863102

3087-
my @actions = gitweb_check_feature('actions');
3103+
my @actions = gitweb_get_feature('actions');
30883104
my %repl = (
30893105
'%' => '%',
30903106
'n' => $project, # project name
@@ -3454,7 +3470,7 @@ sub is_patch_split {
34543470
sub git_difftree_body {
34553471
my ($difftree, $hash, @parents) = @_;
34563472
my ($parent) = $parents[0];
3457-
my ($have_blame) = gitweb_check_feature('blame');
3473+
my $have_blame = gitweb_check_feature('blame');
34583474
print "<div class=\"list_head\">\n";
34593475
if ($#{$difftree} > 10) {
34603476
print(($#{$difftree} + 1) . " files changed:\n");
@@ -3968,7 +3984,7 @@ sub git_project_list_body {
39683984
# actually uses global variable $project
39693985
my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
39703986

3971-
my ($check_forks) = gitweb_check_feature('forks');
3987+
my $check_forks = gitweb_check_feature('forks');
39723988
my @projects = fill_project_list_info($projlist, $check_forks);
39733989

39743990
$order ||= $default_projects_order;
@@ -4428,7 +4444,7 @@ sub git_summary {
44284444
my @taglist = git_get_tags_list(16);
44294445
my @headlist = git_get_heads_list(16);
44304446
my @forklist;
4431-
my ($check_forks) = gitweb_check_feature('forks');
4447+
my $check_forks = gitweb_check_feature('forks');
44324448

44334449
if ($check_forks) {
44344450
@forklist = git_get_projects_list($project);
@@ -4457,7 +4473,7 @@ sub git_summary {
44574473
}
44584474

44594475
# Tag cloud
4460-
my $show_ctags = (gitweb_check_feature('ctags'))[0];
4476+
my $show_ctags = gitweb_check_feature('ctags');
44614477
if ($show_ctags) {
44624478
my $ctags = git_get_project_ctags($project);
44634479
my $cloud = git_populate_project_tagcloud($ctags);
@@ -4747,7 +4763,7 @@ sub git_blob {
47474763
$expires = "+1d";
47484764
}
47494765

4750-
my ($have_blame) = gitweb_check_feature('blame');
4766+
my $have_blame = gitweb_check_feature('blame');
47514767
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
47524768
or die_error(500, "Couldn't cat $file_name, $hash");
47534769
my $mimetype = blob_mimetype($fd, $file_name);
@@ -4840,7 +4856,7 @@ sub git_tree {
48404856
my $ref = format_ref_marker($refs, $hash_base);
48414857
git_header_html();
48424858
my $basedir = '';
4843-
my ($have_blame) = gitweb_check_feature('blame');
4859+
my $have_blame = gitweb_check_feature('blame');
48444860
if (defined $hash_base && (my %co = parse_commit($hash_base))) {
48454861
my @views_nav = ();
48464862
if (defined $file_name) {
@@ -5838,7 +5854,7 @@ sub git_search_help {
58385854
<dt><b>commit</b></dt>
58395855
<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
58405856
EOT
5841-
my ($have_grep) = gitweb_check_feature('grep');
5857+
my $have_grep = gitweb_check_feature('grep');
58425858
if ($have_grep) {
58435859
print <<EOT;
58445860
<dt><b>grep</b></dt>
@@ -5855,7 +5871,7 @@ sub git_search_help {
58555871
<dt><b>committer</b></dt>
58565872
<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
58575873
EOT
5858-
my ($have_pickaxe) = gitweb_check_feature('pickaxe');
5874+
my $have_pickaxe = gitweb_check_feature('pickaxe');
58595875
if ($have_pickaxe) {
58605876
print <<EOT;
58615877
<dt><b>pickaxe</b></dt>
@@ -5907,7 +5923,7 @@ sub git_shortlog {
59075923

59085924
sub git_feed {
59095925
my $format = shift || 'atom';
5910-
my ($have_blame) = gitweb_check_feature('blame');
5926+
my $have_blame = gitweb_check_feature('blame');
59115927

59125928
# Atom: http://www.atomenabled.org/developers/syndication/
59135929
# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ

0 commit comments

Comments
 (0)