Skip to content

Commit 0fa920c

Browse files
theefergitster
authored andcommitted
gitweb: Split git_project_list_body in two functions
Extract the printing of project rows (body/contents of projects list table) on the 'project_list' page into a separate git_project_list_rows function. This makes it easier to reuse the code to print different subsets of the whole project list. [jn: Updated to post restructuring projects list generation] Signed-off-by: Sebastien Cevey <[email protected]> Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4b9447f commit 0fa920c

File tree

1 file changed

+50
-39
lines changed

1 file changed

+50
-39
lines changed

gitweb/gitweb.perl

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,6 +4946,55 @@ sub format_sort_th {
49464946
return $sort_th;
49474947
}
49484948

4949+
sub git_project_list_rows {
4950+
my ($projlist, $from, $to, $check_forks) = @_;
4951+
4952+
$from = 0 unless defined $from;
4953+
$to = $#$projlist if (!defined $to || $#$projlist < $to);
4954+
4955+
my $alternate = 1;
4956+
for (my $i = $from; $i <= $to; $i++) {
4957+
my $pr = $projlist->[$i];
4958+
4959+
if ($alternate) {
4960+
print "<tr class=\"dark\">\n";
4961+
} else {
4962+
print "<tr class=\"light\">\n";
4963+
}
4964+
$alternate ^= 1;
4965+
4966+
if ($check_forks) {
4967+
print "<td>";
4968+
if ($pr->{'forks'}) {
4969+
my $nforks = scalar @{$pr->{'forks'}};
4970+
if ($nforks > 0) {
4971+
print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks"),
4972+
-title => "$nforks forks"}, "+");
4973+
} else {
4974+
print $cgi->span({-title => "$nforks forks"}, "+");
4975+
}
4976+
}
4977+
print "</td>\n";
4978+
}
4979+
print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4980+
-class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
4981+
"<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4982+
-class => "list", -title => $pr->{'descr_long'}},
4983+
esc_html($pr->{'descr'})) . "</td>\n" .
4984+
"<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
4985+
print "<td class=\"". age_class($pr->{'age'}) . "\">" .
4986+
(defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4987+
"<td class=\"link\">" .
4988+
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
4989+
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
4990+
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
4991+
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
4992+
($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
4993+
"</td>\n" .
4994+
"</tr>\n";
4995+
}
4996+
}
4997+
49494998
sub git_project_list_body {
49504999
# actually uses global variable $project
49515000
my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
@@ -5001,47 +5050,9 @@ sub git_project_list_body {
50015050
print "<th></th>\n" . # for links
50025051
"</tr>\n";
50035052
}
5004-
my $alternate = 1;
5005-
for (my $i = $from; $i <= $to; $i++) {
5006-
my $pr = $projects[$i];
50075053

5008-
if ($alternate) {
5009-
print "<tr class=\"dark\">\n";
5010-
} else {
5011-
print "<tr class=\"light\">\n";
5012-
}
5013-
$alternate ^= 1;
5054+
git_project_list_rows(\@projects, $from, $to, $check_forks);
50145055

5015-
if ($check_forks) {
5016-
print "<td>";
5017-
if ($pr->{'forks'}) {
5018-
my $nforks = scalar @{$pr->{'forks'}};
5019-
if ($nforks > 0) {
5020-
print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks"),
5021-
-title => "$nforks forks"}, "+");
5022-
} else {
5023-
print $cgi->span({-title => "$nforks forks"}, "+");
5024-
}
5025-
}
5026-
print "</td>\n";
5027-
}
5028-
print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
5029-
-class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
5030-
"<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
5031-
-class => "list", -title => $pr->{'descr_long'}},
5032-
esc_html($pr->{'descr'})) . "</td>\n" .
5033-
"<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
5034-
print "<td class=\"". age_class($pr->{'age'}) . "\">" .
5035-
(defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
5036-
"<td class=\"link\">" .
5037-
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
5038-
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
5039-
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
5040-
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
5041-
($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
5042-
"</td>\n" .
5043-
"</tr>\n";
5044-
}
50455056
if (defined $extra) {
50465057
print "<tr>\n";
50475058
if ($check_forks) {

0 commit comments

Comments
 (0)