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>
Jakub Narebski committed
Jun 10, 2008 at 19:21 UTC
69913415655839b3add5d930ebbea1be8a5b60a9
1 file changed
+23
-12
gitweb/gitweb.perl
+23
-12
@@ -3559,21 +3559,24 @@ sub git_patchset_body {
3559
3560
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3561
3562
-sub git_project_list_body {
3563
- my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3564
-
3565
- my ($check_forks) = gitweb_check_feature('forks');
3566
-
3562
+# fills project list info (age, description, owner, forks) for each
3563
+# project in the list, removing invalid projects from returned list
3564
+# NOTE: modifies $projlist, but does not remove entries from it
3565
+sub fill_project_list_info {
3566
+ my ($projlist, $check_forks) = @_;
3567
my @projects;
3568
+
3569
+ PROJECT:
3570
foreach my $pr (@$projlist) {
3569
- my (@aa) = git_get_last_activity($pr->{'path'});
3570
- unless (@aa) {
3571
- next;
3571
+ my (@activity) = git_get_last_activity($pr->{'path'});
3572
+ unless (@activity) {
3573
+ next PROJECT;
3574
}
3573
- ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3575
+ ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3576
if (!defined $pr->{'descr'}) {
3577
my $descr = git_get_project_description($pr->{'path'}) || "";
3576
- $pr->{'descr_long'} = to_utf8($descr);
3578
+ $descr = to_utf8($descr);
3579
+ $pr->{'descr_long'} = $descr;
3580
$pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
3581
}
3582
if (!defined $pr->{'owner'}) {
@@ -3585,14 +3588,22 @@ sub git_project_list_body {
3588
($pname !~ /\/$/) &&
3589
(-d "$projectroot/$pname")) {
3590
$pr->{'forks'} = "-d $projectroot/$pname";
3588
- }
3589
- else {
3591
+ } else {
3592
$pr->{'forks'} = 0;
3593
}
3594
}
3595
push @projects, $pr;
3596
}
3597
3598
+ return @projects;
3599
+}
3600
+
3601
+sub git_project_list_body {
3602
+ my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3603
+
3604
+ my ($check_forks) = gitweb_check_feature('forks');
3605
+ my @projects = fill_project_list_info($projlist, $check_forks);
3606
+
3607
$order ||= $default_projects_order;
3608
$from = 0 unless defined $from;
3609
$to = $#projects if (!defined $to || $#projects < $to);