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 <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed Feb 23, 2012 at 16:54 UTC 14b289bdf7c31176dc525cbe81173ec636598782
1 file changed +26 -8
gitweb/gitweb.perl
+26 -8
@@ -5188,6 +5188,20 @@ sub git_project_search_form {
5188 print "</div>\n";
5189 }
5190
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 +
5205 # fills project list info (age, description, owner, category, forks)
5206 # for each project in the list, removing invalid projects from
5207 # returned list
@@ -5199,24 +5213,28 @@ sub fill_project_list_info {
5213 my $show_ctags = gitweb_check_feature('ctags');
5214 PROJECT:
5215 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;
5222 }
5206 - ($pr->{'age'}, $pr->{'age_string'}) = @activity;
5207 - if (!defined $pr->{'descr'}) {
5223 + if (project_info_needs_filling($pr, 'descr', 'descr_long')) {
5224 my $descr = git_get_project_description($pr->{'path'}) || "";
5225 $descr = to_utf8($descr);
5226 $pr->{'descr_long'} = $descr;
5227 $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
5228 }
5213 - if (!defined $pr->{'owner'}) {
5229 + if (project_info_needs_filling($pr, 'owner')) {
5230 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
5231 }
5216 - if ($show_ctags) {
5232 + if ($show_ctags &&
5233 + project_info_needs_filling($pr, 'ctags')) {
5234 $pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
5235 }
5219 - if ($projects_list_group_categories && !defined $pr->{'category'}) {
5236 + if ($projects_list_group_categories &&
5237 + project_info_needs_filling($pr, 'category')) {
5238 my $cat = git_get_project_category($pr->{'path'}) ||
5239 $project_list_default_category;
5240 $pr->{'category'} = to_utf8($cat);