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 <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jakub Narebski committed
Feb 23, 2012 at 16:54 UTC
2e3291ae1dc7790aa08c1eeb476fbf1c6d3a1ed9
1 file changed
+25
-8
gitweb/gitweb.perl
+25
-8
@@ -5202,39 +5202,56 @@ sub project_info_needs_filling {
5202
return;
5203
}
5204
5205
-# fills project list info (age, description, owner, category, forks)
5205
+# fills project list info (age, description, owner, category, forks, etc.)
5206
# 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
+#
5220
# NOTE: modifies $projlist, but does not remove entries from it
5221
sub fill_project_list_info {
5210
- my $projlist = shift;
5222
+ my ($projlist, @wanted_keys) = @_;
5223
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
+ }
5229
5230
my $show_ctags = gitweb_check_feature('ctags');
5231
PROJECT:
5232
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'))) {
5234
my (@activity) = git_get_last_activity($pr->{'path'});
5235
unless (@activity) {
5236
next PROJECT;
5237
}
5238
($pr->{'age'}, $pr->{'age_string'}) = @activity;
5239
}
5223
- if (project_info_needs_filling($pr, 'descr', 'descr_long')) {
5240
+ if (project_info_needs_filling($pr, $filter_set->('descr', 'descr_long'))) {
5241
my $descr = git_get_project_description($pr->{'path'}) || "";
5242
$descr = to_utf8($descr);
5243
$pr->{'descr_long'} = $descr;
5244
$pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
5245
}
5229
- if (project_info_needs_filling($pr, 'owner')) {
5246
+ if (project_info_needs_filling($pr, $filter_set->('owner'))) {
5247
$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
5248
}
5249
if ($show_ctags &&
5233
- project_info_needs_filling($pr, 'ctags')) {
5250
+ project_info_needs_filling($pr, $filter_set->('ctags'))) {
5251
$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
5252
}
5253
if ($projects_list_group_categories &&
5237
- project_info_needs_filling($pr, 'category')) {
5254
+ project_info_needs_filling($pr, $filter_set->('category'))) {
5255
my $cat = git_get_project_category($pr->{'path'}) ||
5256
$project_list_default_category;
5257
$pr->{'category'} = to_utf8($cat);