@@ -2987,6 +2987,10 @@ sub search_projects_list {
2987
2987
return @$projlist
2988
2988
unless ($tagfilter || $searchtext );
2989
2989
2990
+ # searching projects require filling to be run before it;
2991
+ fill_project_list_info($projlist ,
2992
+ $tagfilter ? ' ctags' : (),
2993
+ $searchtext ? (' path' , ' descr' ) : ());
2990
2994
my @projects ;
2991
2995
PROJECT:
2992
2996
foreach my $pr (@$projlist ) {
@@ -5188,35 +5192,70 @@ sub git_project_search_form {
5188
5192
print " </div>\n " ;
5189
5193
}
5190
5194
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.)
5192
5210
# 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
+ #
5194
5224
# NOTE: modifies $projlist, but does not remove entries from it
5195
5225
sub fill_project_list_info {
5196
- my $projlist = shift ;
5226
+ my ( $projlist , @wanted_keys ) = @_ ;
5197
5227
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
+ }
5198
5233
5199
5234
my $show_ctags = gitweb_check_feature(' ctags' );
5200
5235
PROJECT:
5201
5236
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 ;
5205
5243
}
5206
- ($pr -> {' age' }, $pr -> {' age_string' }) = @activity ;
5207
- if (!defined $pr -> {' descr' }) {
5244
+ if (project_info_needs_filling($pr , $filter_set -> (' descr' , ' descr_long' ))) {
5208
5245
my $descr = git_get_project_description($pr -> {' path' }) || " " ;
5209
5246
$descr = to_utf8($descr );
5210
5247
$pr -> {' descr_long' } = $descr ;
5211
5248
$pr -> {' descr' } = chop_str($descr , $projects_list_description_width , 5);
5212
5249
}
5213
- if (! defined $pr -> { ' owner' } ) {
5250
+ if (project_info_needs_filling( $pr , $filter_set -> ( ' owner' )) ) {
5214
5251
$pr -> {' owner' } = git_get_project_owner(" $pr ->{'path'}" ) || " " ;
5215
5252
}
5216
- if ($show_ctags ) {
5253
+ if ($show_ctags &&
5254
+ project_info_needs_filling($pr , $filter_set -> (' ctags' ))) {
5217
5255
$pr -> {' ctags' } = git_get_project_ctags($pr -> {' path' });
5218
5256
}
5219
- if ($projects_list_group_categories && !defined $pr -> {' category' }) {
5257
+ if ($projects_list_group_categories &&
5258
+ project_info_needs_filling($pr , $filter_set -> (' category' ))) {
5220
5259
my $cat = git_get_project_category($pr -> {' path' }) ||
5221
5260
$project_list_default_category ;
5222
5261
$pr -> {' category' } = to_utf8($cat );
@@ -5352,12 +5391,13 @@ sub git_project_list_body {
5352
5391
# filtering out forks before filling info allows to do less work
5353
5392
@projects = filter_forks_from_projects_list(\@projects )
5354
5393
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
5357
5395
@projects = search_projects_list(\@projects ,
5358
5396
' searchtext' => $searchtext ,
5359
5397
' tagfilter' => $tagfilter )
5360
5398
if ($tagfilter || $searchtext );
5399
+ # fill the rest
5400
+ @projects = fill_project_list_info(\@projects );
5361
5401
5362
5402
$order ||= $default_projects_order ;
5363
5403
$from = 0 unless defined $from ;
0 commit comments