Browse Source

gitweb: Separate filling list of projects info

Extract filling project list info, i.e. adding age, description, owner
and forks information, into fill_project_list_info() subroutine.  This
is preparation for smart pagination and smart searching (to make it
possible to calculate/generate info only for those projects which will
be shown).

Small changes compared to original version to improve readability
(comments, names of variables, named loops).

Additionally, store both full ('descr_long') and shortened ('descr')
project description in Perl's internal form (using to_utf8).

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Jakub Narebski 17 years ago committed by Junio C Hamano
parent
commit
6991341565
  1. 35
      gitweb/gitweb.perl

35
gitweb/gitweb.perl

@ -3559,21 +3559,24 @@ sub git_patchset_body {


# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


sub git_project_list_body { # fills project list info (age, description, owner, forks) for each
my ($projlist, $order, $from, $to, $extra, $no_header) = @_; # project in the list, removing invalid projects from returned list

# NOTE: modifies $projlist, but does not remove entries from it
my ($check_forks) = gitweb_check_feature('forks'); sub fill_project_list_info {

my ($projlist, $check_forks) = @_;
my @projects; my @projects;

PROJECT:
foreach my $pr (@$projlist) { foreach my $pr (@$projlist) {
my (@aa) = git_get_last_activity($pr->{'path'}); my (@activity) = git_get_last_activity($pr->{'path'});
unless (@aa) { unless (@activity) {
next; next PROJECT;
} }
($pr->{'age'}, $pr->{'age_string'}) = @aa; ($pr->{'age'}, $pr->{'age_string'}) = @activity;
if (!defined $pr->{'descr'}) { if (!defined $pr->{'descr'}) {
my $descr = git_get_project_description($pr->{'path'}) || ""; my $descr = git_get_project_description($pr->{'path'}) || "";
$pr->{'descr_long'} = to_utf8($descr); $descr = to_utf8($descr);
$pr->{'descr_long'} = $descr;
$pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5); $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
} }
if (!defined $pr->{'owner'}) { if (!defined $pr->{'owner'}) {
@ -3585,14 +3588,22 @@ sub git_project_list_body {
($pname !~ /\/$/) && ($pname !~ /\/$/) &&
(-d "$projectroot/$pname")) { (-d "$projectroot/$pname")) {
$pr->{'forks'} = "-d $projectroot/$pname"; $pr->{'forks'} = "-d $projectroot/$pname";
} } else {
else {
$pr->{'forks'} = 0; $pr->{'forks'} = 0;
} }
} }
push @projects, $pr; push @projects, $pr;
} }


return @projects;
}

sub git_project_list_body {
my ($projlist, $order, $from, $to, $extra, $no_header) = @_;

my ($check_forks) = gitweb_check_feature('forks');
my @projects = fill_project_list_info($projlist, $check_forks);

$order ||= $default_projects_order; $order ||= $default_projects_order;
$from = 0 unless defined $from; $from = 0 unless defined $from;
$to = $#projects if (!defined $to || $#projects < $to); $to = $#projects if (!defined $to || $#projects < $to);

Loading…
Cancel
Save