Skip to content

Commit 2e3291a

Browse files
jnarebgitster
authored andcommitted
gitweb: Option for filling only specified info in fill_project_list_info
Enhance fill_project_list_info() subroutine to accept optional parameters that specify which fields in project information needs to be filled. If none are specified then fill_project_list_info() behaves as it used to, and ensure that all project info is filled. This is in preparation of future lazy filling of project info in project search and pagination of sorted list of projects. Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 14b289b commit 2e3291a

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

gitweb/gitweb.perl

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5202,39 +5202,56 @@ sub project_info_needs_filling {
52025202
return;
52035203
}
52045204

5205-
# fills project list info (age, description, owner, category, forks)
5205+
# fills project list info (age, description, owner, category, forks, etc.)
52065206
# for each project in the list, removing invalid projects from
5207-
# returned list
5207+
# returned list, or fill only specified info.
5208+
#
5209+
# Invalid projects are removed from the returned list if and only if you
5210+
# ask 'age' or 'age_string' to be filled, because they are the only fields
5211+
# that run unconditionally git command that requires repository, and
5212+
# therefore do always check if project repository is invalid.
5213+
#
5214+
# USAGE:
5215+
# * fill_project_list_info(\@project_list, 'descr_long', 'ctags')
5216+
# ensures that 'descr_long' and 'ctags' fields are filled
5217+
# * @project_list = fill_project_list_info(\@project_list)
5218+
# ensures that all fields are filled (and invalid projects removed)
5219+
#
52085220
# NOTE: modifies $projlist, but does not remove entries from it
52095221
sub fill_project_list_info {
5210-
my $projlist = shift;
5222+
my ($projlist, @wanted_keys) = @_;
52115223
my @projects;
5224+
my $filter_set = sub { return @_; };
5225+
if (@wanted_keys) {
5226+
my %wanted_keys = map { $_ => 1 } @wanted_keys;
5227+
$filter_set = sub { return grep { $wanted_keys{$_} } @_; };
5228+
}
52125229

52135230
my $show_ctags = gitweb_check_feature('ctags');
52145231
PROJECT:
52155232
foreach my $pr (@$projlist) {
5216-
if (project_info_needs_filling($pr, 'age', 'age_string')) {
5233+
if (project_info_needs_filling($pr, $filter_set->('age', 'age_string'))) {
52175234
my (@activity) = git_get_last_activity($pr->{'path'});
52185235
unless (@activity) {
52195236
next PROJECT;
52205237
}
52215238
($pr->{'age'}, $pr->{'age_string'}) = @activity;
52225239
}
5223-
if (project_info_needs_filling($pr, 'descr', 'descr_long')) {
5240+
if (project_info_needs_filling($pr, $filter_set->('descr', 'descr_long'))) {
52245241
my $descr = git_get_project_description($pr->{'path'}) || "";
52255242
$descr = to_utf8($descr);
52265243
$pr->{'descr_long'} = $descr;
52275244
$pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
52285245
}
5229-
if (project_info_needs_filling($pr, 'owner')) {
5246+
if (project_info_needs_filling($pr, $filter_set->('owner'))) {
52305247
$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
52315248
}
52325249
if ($show_ctags &&
5233-
project_info_needs_filling($pr, 'ctags')) {
5250+
project_info_needs_filling($pr, $filter_set->('ctags'))) {
52345251
$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
52355252
}
52365253
if ($projects_list_group_categories &&
5237-
project_info_needs_filling($pr, 'category')) {
5254+
project_info_needs_filling($pr, $filter_set->('category'))) {
52385255
my $cat = git_get_project_category($pr->{'path'}) ||
52395256
$project_list_default_category;
52405257
$pr->{'category'} = to_utf8($cat);

0 commit comments

Comments
 (0)