git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] gitweb: Split git_project_list_body in two functions

From
Jakub Narebski <jnareb@gmail.com>
Date
Apr 29, 2011, 17:51 UTC
Message-ID
<1304099521-27617-5-git-send-email-jnareb@gmail.com>
In-Reply-To
<1304099521-27617-1-git-send-email-jnareb@gmail.com>
From: Sebastien Cevey <seb@cine7.net>

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>
---
This patch and subsequent patches were sent to git mailing list
(before rebasing on top of 'ctags' improvements) as
  [RFC/PATCH 0/3] gitweb: Categories support
  http://thread.gmane.org/gmane.comp.version-control.git/168616

This subseries is long in wait port of Sebastien Cevey series from December 2008

  http://thread.gmane.org/gmane.comp.version-control.git/102844

to modern gitweb. It was waiting for restructuring of projects list generation that is part of this series.

Uwe, it might be an alternative to use of ctags (content tags, aka project labels).

 gitweb/gitweb.perl |   89 +++++++++++++++++++++++++++++-----------------------
 1 files changed, 50 insertions(+), 39 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index e81c27d..f8d5722 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4946,6 +4946,55 @@ sub format_sort_th {
 	return $sort_th;
 }
 
+sub git_project_list_rows {
+	my ($projlist, $from, $to, $check_forks) = @_;
+
+	$from = 0 unless defined $from;
+	$to = $#$projlist if (!defined $to || $#$projlist < $to);
+
+	my $alternate = 1;
+	for (my $i = $from; $i <= $to; $i++) {
+		my $pr = $projlist->[$i];
+
+		if ($alternate) {
+			print "<tr class=\"dark\">\n";
+		} else {
+			print "<tr class=\"light\">\n";
+		}
+		$alternate ^= 1;
+
+		if ($check_forks) {
+			print "<td>";
+			if ($pr->{'forks'}) {
+				my $nforks = scalar @{$pr->{'forks'}};
+				if ($nforks > 0) {
+					print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks"),
+					               -title => "$nforks forks"}, "+");
+				} else {
+					print $cgi->span({-title => "$nforks forks"}, "+");
+				}
+			}
+			print "</td>\n";
+		}
+		print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
+		                        -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
+		      "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
+		                        -class => "list", -title => $pr->{'descr_long'}},
+		                        esc_html($pr->{'descr'})) . "</td>\n" .
+		      "<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
+		print "<td class=\"". age_class($pr->{'age'}) . "\">" .
+		      (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
+		      "<td class=\"link\">" .
+		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary")   . " | " .
+		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
+		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
+		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
+		      ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
+		      "</td>\n" .
+		      "</tr>\n";
+	}
+}
+
 sub git_project_list_body {
 	# actually uses global variable $project
 	my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
@@ -5001,47 +5050,9 @@ sub git_project_list_body {
 		print "<th></th>\n" . # for links
 		      "</tr>\n";
 	}
-	my $alternate = 1;
-	for (my $i = $from; $i <= $to; $i++) {
-		my $pr = $projects[$i];
 
-		if ($alternate) {
-			print "<tr class=\"dark\">\n";
-		} else {
-			print "<tr class=\"light\">\n";
-		}
-		$alternate ^= 1;
+	git_project_list_rows(\@projects, $from, $to, $check_forks);
 
-		if ($check_forks) {
-			print "<td>";
-			if ($pr->{'forks'}) {
-				my $nforks = scalar @{$pr->{'forks'}};
-				if ($nforks > 0) {
-					print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks"),
-					               -title => "$nforks forks"}, "+");
-				} else {
-					print $cgi->span({-title => "$nforks forks"}, "+");
-				}
-			}
-			print "</td>\n";
-		}
-		print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
-		                        -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
-		      "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
-		                        -class => "list", -title => $pr->{'descr_long'}},
-		                        esc_html($pr->{'descr'})) . "</td>\n" .
-		      "<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
-		print "<td class=\"". age_class($pr->{'age'}) . "\">" .
-		      (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
-		      "<td class=\"link\">" .
-		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary")   . " | " .
-		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
-		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
-		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
-		      ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
-		      "</td>\n" .
-		      "</tr>\n";
-	}
 	if (defined $extra) {
 		print "<tr>\n";
 		if ($check_forks) {
-- 
1.7.3
Previous: Jakub NarebskiNext: Jakub Narebski
Message 6 of 13 in “gitweb: Improve ctags, introduce categories”
  1. 0/6 gitweb: Improve ctags, introduce categoriesJakub Narebski, Apr 29, 2011
  2. 1/6 gitweb: Restructure projects list generationJakub Narebski, Apr 29, 2011
  3. Jakub NarebskiMay 7, 2011
  4. 2/6 gitweb: Change the way "content tags" ('ctags') are handledJakub Narebski, Apr 29, 2011
  5. 3/6 gitweb: Mark matched 'ctag' / contents tag (?by_tag=foo)Jakub Narebski, Apr 29, 2011
  6. 4/6 gitweb: Split git_project_list_body in two functionsJakub Narebski, Apr 29, 2011
  7. 5/6 gitweb: Modularized git_get_project_description to be more genericJakub Narebski, Apr 29, 2011
  8. 6/6 gitweb: Optional grouping of projects by categoryJakub Narebski, Apr 29, 2011
  9. Junio C HamanoApr 29, 2011
  10. Jakub NarebskiApr 29, 2011
  11. Øyvind A. HolmApr 30, 2011
  12. Jakub NarebskiMay 3, 2011
  13. git-send-email: Do not encode Subject if not required (was: git-send-email and non 7bit clean message)Jakub Narebski, May 4, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.