]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: Option for filling only specified info in fill_project_list_info
authorJakub Narebski <redacted>
Thu, 23 Feb 2012 15:54:47 +0000 (16:54 +0100)
committerLady <redacted>
Mon, 6 Apr 2026 04:51:32 +0000 (00:51 -0400)
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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl

index a74f645bb05c538de6ffe39713c035f4867ecb044e9412cc3686ac1d71e45f7e..a4b983718ea52f51b6dea8bc5154f0bed3bf1374af3bc1ca8348cc95c0a1265c 100755 (executable)
@@ -5203,39 +5203,56 @@ sub project_info_needs_filling {
        return;
 }
 
-# fills project list info (age, description, owner, category, forks)
+# fills project list info (age, description, owner, category, forks, etc.)
 # for each project in the list, removing invalid projects from
-# returned list
+# returned list, or fill only specified info.
+#
+# Invalid projects are removed from the returned list if and only if you
+# ask 'age' or 'age_string' to be filled, because they are the only fields
+# that run unconditionally git command that requires repository, and
+# therefore do always check if project repository is invalid.
+#
+# USAGE:
+# * fill_project_list_info(\@project_list, 'descr_long', 'ctags')
+#   ensures that 'descr_long' and 'ctags' fields are filled
+# * @project_list = fill_project_list_info(\@project_list)
+#   ensures that all fields are filled (and invalid projects removed)
+#
 # NOTE: modifies $projlist, but does not remove entries from it
 sub fill_project_list_info {
-       my $projlist = shift;
+       my ($projlist, @wanted_keys) = @_;
        my @projects;
+       my $filter_set = sub { return @_; };
+       if (@wanted_keys) {
+               my %wanted_keys = map { $_ => 1 } @wanted_keys;
+               $filter_set = sub { return grep { $wanted_keys{$_} } @_; };
+       }
 
        my $show_ctags = gitweb_check_feature('ctags');
  PROJECT:
        foreach my $pr (@$projlist) {
-               if (project_info_needs_filling($pr, 'age', 'age_string')) {
+               if (project_info_needs_filling($pr, $filter_set->('age', 'age_string'))) {
                        my (@activity) = git_get_last_activity($pr->{'path'});
                        unless (@activity) {
                                next PROJECT;
                        }
                        ($pr->{'age'}, $pr->{'age_string'}) = @activity;
                }
-               if (project_info_needs_filling($pr, 'descr', 'descr_long')) {
+               if (project_info_needs_filling($pr, $filter_set->('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 (project_info_needs_filling($pr, 'owner')) {
+               if (project_info_needs_filling($pr, $filter_set->('owner'))) {
                        $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
                }
                if ($show_ctags &&
-                   project_info_needs_filling($pr, 'ctags')) {
+                   project_info_needs_filling($pr, $filter_set->('ctags'))) {
                        $pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
                }
                if ($projects_list_group_categories &&
-                   project_info_needs_filling($pr, 'category')) {
+                   project_info_needs_filling($pr, $filter_set->('category'))) {
                        my $cat = git_get_project_category($pr->{'path'}) ||
                                                           $project_list_default_category;
                        $pr->{'category'} = to_utf8($cat);
This page took 0.134196 seconds and 4 git commands to generate.