From: Jakub Narebski Date: Thu, 23 Feb 2012 15:54:46 +0000 (+0100) Subject: gitweb: Refactor checking if part of project info need filling X-Git-Tag: v1.7.10-rc0~16^2~6 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=14b289bdf7c31176dc525cbe81173ec636598782;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 3fc7380a5..3aeeb8b34 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -5188,6 +5188,20 @@ sub git_project_search_form { print "\n"; } +# entry for given @keys needs filling if at least one of keys in list +# is not present in %$project_info +sub project_info_needs_filling { + my ($project_info, @keys) = @_; + + # return List::MoreUtils::any { !exists $project_info->{$_} } @keys; + foreach my $key (@keys) { + if (!exists $project_info->{$key}) { + return 1; + } + } + return; +} + # fills project list info (age, description, owner, category, forks) # for each project in the list, removing invalid projects from # returned list @@ -5199,24 +5213,28 @@ sub fill_project_list_info { my $show_ctags = gitweb_check_feature('ctags'); PROJECT: foreach my $pr (@$projlist) { - my (@activity) = git_get_last_activity($pr->{'path'}); - unless (@activity) { - next PROJECT; + if (project_info_needs_filling($pr, 'age', 'age_string')) { + my (@activity) = git_get_last_activity($pr->{'path'}); + unless (@activity) { + next PROJECT; + } + ($pr->{'age'}, $pr->{'age_string'}) = @activity; } - ($pr->{'age'}, $pr->{'age_string'}) = @activity; - if (!defined $pr->{'descr'}) { + if (project_info_needs_filling($pr, 'descr', 'descr_long')) { my $descr = git_get_project_description($pr->{'path'}) || ""; $descr = to_utf8($descr); $pr->{'descr_long'} = $descr; $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5); } - if (!defined $pr->{'owner'}) { + if (project_info_needs_filling($pr, 'owner')) { $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || ""; } - if ($show_ctags) { + if ($show_ctags && + project_info_needs_filling($pr, 'ctags')) { $pr->{'ctags'} = git_get_project_ctags($pr->{'path'}); } - if ($projects_list_group_categories && !defined $pr->{'category'}) { + if ($projects_list_group_categories && + project_info_needs_filling($pr, 'category')) { my $cat = git_get_project_category($pr->{'path'}) || $project_list_default_category; $pr->{'category'} = to_utf8($cat);