@matheusbsbs / matheus-bagliano / commits / 0fa920c35c
Fork 0

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 <seb@cine7.net> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sebastien Cevey committed Apr 29, 2011 at 19:51 UTC 0fa920c35c2617d7c1756b1e2bf5c56a81db3232
1 file changed +50 -39
gitweb/gitweb.perl
+50 -39
@@ -4946,6 +4946,55 @@ sub format_sort_th {
4946 return $sort_th;
4947 }
4948
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 +
4998 sub git_project_list_body {
4999 # actually uses global variable $project
5000 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
@@ -5001,47 +5050,9 @@ sub git_project_list_body {
5050 print "<th></th>\n" . # for links
5051 "</tr>\n";
5052 }
5004 - my $alternate = 1;
5005 - for (my $i = $from; $i <= $to; $i++) {
5006 - my $pr = $projects[$i];
5053
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);
5055
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 - }
5056 if (defined $extra) {
5057 print "<tr>\n";
5058 if ($check_forks) {