Skip to content

Commit 14b289b

Browse files
jnarebgitster
authored andcommitted
gitweb: Refactor checking if part of project info need filling
Extract the check if given keys (given parts) of project info needs to be filled into project_info_needs_filling() subroutine. It is for now a thin wrapper around "!exists $project_info->{$key}". Note that !defined was replaced by more correct !exists. While at it uniquify treating of all project info, adding checks for 'age' field before running git_get_last_activity(), and also checking for all keys filled in code protected by conditional, and not only one. The code now looks like this foreach my $project (@$project_list) { if (given keys need to be filled) { fill given keys } ... } Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b0d66b5 commit 14b289b

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

gitweb/gitweb.perl

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5188,6 +5188,20 @@ sub git_project_search_form {
51885188
print "</div>\n";
51895189
}
51905190

5191+
# entry for given @keys needs filling if at least one of keys in list
5192+
# is not present in %$project_info
5193+
sub project_info_needs_filling {
5194+
my ($project_info, @keys) = @_;
5195+
5196+
# return List::MoreUtils::any { !exists $project_info->{$_} } @keys;
5197+
foreach my $key (@keys) {
5198+
if (!exists $project_info->{$key}) {
5199+
return 1;
5200+
}
5201+
}
5202+
return;
5203+
}
5204+
51915205
# fills project list info (age, description, owner, category, forks)
51925206
# for each project in the list, removing invalid projects from
51935207
# returned list
@@ -5199,24 +5213,28 @@ sub fill_project_list_info {
51995213
my $show_ctags = gitweb_check_feature('ctags');
52005214
PROJECT:
52015215
foreach my $pr (@$projlist) {
5202-
my (@activity) = git_get_last_activity($pr->{'path'});
5203-
unless (@activity) {
5204-
next PROJECT;
5216+
if (project_info_needs_filling($pr, 'age', 'age_string')) {
5217+
my (@activity) = git_get_last_activity($pr->{'path'});
5218+
unless (@activity) {
5219+
next PROJECT;
5220+
}
5221+
($pr->{'age'}, $pr->{'age_string'}) = @activity;
52055222
}
5206-
($pr->{'age'}, $pr->{'age_string'}) = @activity;
5207-
if (!defined $pr->{'descr'}) {
5223+
if (project_info_needs_filling($pr, 'descr', 'descr_long')) {
52085224
my $descr = git_get_project_description($pr->{'path'}) || "";
52095225
$descr = to_utf8($descr);
52105226
$pr->{'descr_long'} = $descr;
52115227
$pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
52125228
}
5213-
if (!defined $pr->{'owner'}) {
5229+
if (project_info_needs_filling($pr, 'owner')) {
52145230
$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
52155231
}
5216-
if ($show_ctags) {
5232+
if ($show_ctags &&
5233+
project_info_needs_filling($pr, 'ctags')) {
52175234
$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
52185235
}
5219-
if ($projects_list_group_categories && !defined $pr->{'category'}) {
5236+
if ($projects_list_group_categories &&
5237+
project_info_needs_filling($pr, 'category')) {
52205238
my $cat = git_get_project_category($pr->{'path'}) ||
52215239
$project_list_default_category;
52225240
$pr->{'category'} = to_utf8($cat);

0 commit comments

Comments
 (0)