@@ -2987,6 +2987,10 @@ sub search_projects_list {
29872987 return @$projlist
29882988 unless ($tagfilter || $searchtext );
29892989
2990+ # searching projects require filling to be run before it;
2991+ fill_project_list_info($projlist ,
2992+ $tagfilter ? ' ctags' : (),
2993+ $searchtext ? (' path' , ' descr' ) : ());
29902994 my @projects ;
29912995 PROJECT:
29922996 foreach my $pr (@$projlist ) {
@@ -5188,35 +5192,70 @@ sub git_project_search_form {
51885192 print " </div>\n " ;
51895193}
51905194
5191- # fills project list info (age, description, owner, category, forks)
5195+ # entry for given @keys needs filling if at least one of keys in list
5196+ # is not present in %$project_info
5197+ sub project_info_needs_filling {
5198+ my ($project_info , @keys ) = @_ ;
5199+
5200+ # return List::MoreUtils::any { !exists $project_info->{$_} } @keys;
5201+ foreach my $key (@keys ) {
5202+ if (!exists $project_info -> {$key }) {
5203+ return 1;
5204+ }
5205+ }
5206+ return ;
5207+ }
5208+
5209+ # fills project list info (age, description, owner, category, forks, etc.)
51925210# for each project in the list, removing invalid projects from
5193- # returned list
5211+ # returned list, or fill only specified info.
5212+ #
5213+ # Invalid projects are removed from the returned list if and only if you
5214+ # ask 'age' or 'age_string' to be filled, because they are the only fields
5215+ # that run unconditionally git command that requires repository, and
5216+ # therefore do always check if project repository is invalid.
5217+ #
5218+ # USAGE:
5219+ # * fill_project_list_info(\@project_list, 'descr_long', 'ctags')
5220+ # ensures that 'descr_long' and 'ctags' fields are filled
5221+ # * @project_list = fill_project_list_info(\@project_list)
5222+ # ensures that all fields are filled (and invalid projects removed)
5223+ #
51945224# NOTE: modifies $projlist, but does not remove entries from it
51955225sub fill_project_list_info {
5196- my $projlist = shift ;
5226+ my ( $projlist , @wanted_keys ) = @_ ;
51975227 my @projects ;
5228+ my $filter_set = sub { return @_ ; };
5229+ if (@wanted_keys ) {
5230+ my %wanted_keys = map { $_ => 1 } @wanted_keys ;
5231+ $filter_set = sub { return grep { $wanted_keys {$_ } } @_ ; };
5232+ }
51985233
51995234 my $show_ctags = gitweb_check_feature(' ctags' );
52005235 PROJECT:
52015236 foreach my $pr (@$projlist ) {
5202- my (@activity ) = git_get_last_activity($pr -> {' path' });
5203- unless (@activity ) {
5204- next PROJECT;
5237+ if (project_info_needs_filling($pr , $filter_set -> (' age' , ' age_string' ))) {
5238+ my (@activity ) = git_get_last_activity($pr -> {' path' });
5239+ unless (@activity ) {
5240+ next PROJECT;
5241+ }
5242+ ($pr -> {' age' }, $pr -> {' age_string' }) = @activity ;
52055243 }
5206- ($pr -> {' age' }, $pr -> {' age_string' }) = @activity ;
5207- if (!defined $pr -> {' descr' }) {
5244+ if (project_info_needs_filling($pr , $filter_set -> (' descr' , ' descr_long' ))) {
52085245 my $descr = git_get_project_description($pr -> {' path' }) || " " ;
52095246 $descr = to_utf8($descr );
52105247 $pr -> {' descr_long' } = $descr ;
52115248 $pr -> {' descr' } = chop_str($descr , $projects_list_description_width , 5);
52125249 }
5213- if (! defined $pr -> { ' owner' } ) {
5250+ if (project_info_needs_filling( $pr , $filter_set -> ( ' owner' )) ) {
52145251 $pr -> {' owner' } = git_get_project_owner(" $pr ->{'path'}" ) || " " ;
52155252 }
5216- if ($show_ctags ) {
5253+ if ($show_ctags &&
5254+ project_info_needs_filling($pr , $filter_set -> (' ctags' ))) {
52175255 $pr -> {' ctags' } = git_get_project_ctags($pr -> {' path' });
52185256 }
5219- if ($projects_list_group_categories && !defined $pr -> {' category' }) {
5257+ if ($projects_list_group_categories &&
5258+ project_info_needs_filling($pr , $filter_set -> (' category' ))) {
52205259 my $cat = git_get_project_category($pr -> {' path' }) ||
52215260 $project_list_default_category ;
52225261 $pr -> {' category' } = to_utf8($cat );
@@ -5352,12 +5391,13 @@ sub git_project_list_body {
53525391 # filtering out forks before filling info allows to do less work
53535392 @projects = filter_forks_from_projects_list(\@projects )
53545393 if ($check_forks );
5355- @projects = fill_project_list_info(\@projects );
5356- # searching projects require filling to be run before it
5394+ # search_projects_list pre-fills required info
53575395 @projects = search_projects_list(\@projects ,
53585396 ' searchtext' => $searchtext ,
53595397 ' tagfilter' => $tagfilter )
53605398 if ($tagfilter || $searchtext );
5399+ # fill the rest
5400+ @projects = fill_project_list_info(\@projects );
53615401
53625402 $order ||= $default_projects_order ;
53635403 $from = 0 unless defined $from ;
0 commit comments