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

[PATCH 2/2] gitweb: add section support to gitweb project listing.

From
GBGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Date
Jul 29, 2008, 02:34 UTC
Message-ID
<1217298868-16513-3-git-send-email-barbieri@profusion.mobi>
In-Reply-To
<1217298868-16513-2-git-send-email-barbieri@profusion.mobi>

Section headers will be optionally displayed when projects dirnames or owner names changes (depending on sort order), making it easier to find projects in large setups.

Signed-off-by: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
---
 gitweb/gitweb.css  |    7 +++++
 gitweb/gitweb.perl |   73 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 79 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css
index aa0eeca..44abc4c 100644
--- a/gitweb/gitweb.css
+++ b/gitweb/gitweb.css
@@ -235,6 +235,13 @@ tr.dark:hover {
 	background-color: #edece6;
 }
 
+tr.section td {
+	background-color: #d9d8d1;
+	border-top: 1px solid #000000;
+	border-left: 1px solid #000000;
+	font-weight: bold;
+}
+
 td {
 	padding: 2px 5px;
 	font-size: 100%;
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index c5675cf..c99cea3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -15,7 +15,7 @@ use CGI::Carp qw(fatalsToBrowser);
 use Encode;
 use Fcntl ':mode';
 use File::Find qw();
-use File::Basename qw(basename);
+use File::Basename qw(basename dirname);
 binmode STDOUT, ':utf8';
 
 BEGIN {
@@ -82,6 +82,9 @@ our $projects_list_description_width = 25;
 # valid values are none, project, descr, owner, and age
 our $default_projects_order = "project";
 
+# use sections to separate projects by dirname, helps usability
+our $use_sections = 1;
+
 # show repository only if this file exists
 # (only effective if this variable evaluates to true)
 our $export_ok = "++GITWEB_EXPORT_OK++";
@@ -3631,6 +3634,66 @@ sub print_sort_th_num {
 	print_sort_th(0, @_);
 }
 
+sub print_section_tr {
+	my ($n_cols, $section) = @_;
+	print "<tr class=\"section\"><td colspan=\"$n_cols\">$section</td></tr>\n";
+}
+
+sub print_section_internal {
+	my ($order, $n_cols, $current, $getter) = @_;
+	my $current_value = $getter->($current);
+
+	if (!$current_value) {
+		return 0;
+	}
+
+	my $last_value = '';
+	if ($current > 0) {
+		$last_value = $getter->($current - 1);
+	}
+
+	if ($current_value ne $last_value) {
+		print_section_tr($n_cols, $current_value);
+		return 1;
+	}
+
+	return 0;
+}
+
+sub print_section_project {
+	my ($order, $n_cols, $current, $projects) = @_;
+
+	sub get_section_project {
+		my ($index) = @_;
+		return dirname(@$projects[$index]->{'path'});
+	}
+
+	return print_section_internal($order, $n_cols, $current, \&get_section_project);
+}
+
+sub print_section_owner {
+	my ($order, $n_cols, $current, $projects) = @_;
+
+	sub get_section_owner {
+		my ($index) = @_;
+		return @$projects[$index]->{'owner'};
+	}
+
+	return print_section_internal($order, $n_cols, $current, \&get_section_owner);
+}
+
+sub print_section {
+	my ($order, $n_cols, $current, $projects) = @_;
+
+	if ($order eq 'project') {
+		return print_section_project($order, $n_cols, $current, $projects);
+	} elsif ($order eq 'owner') {
+		return print_section_owner($order, $n_cols, $current, $projects);
+	}
+
+	return 0;
+}
+
 sub git_project_list_body {
 	my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
 
@@ -3658,9 +3721,17 @@ sub git_project_list_body {
 		print "<th></th>\n" . # for links
 		      "</tr>\n";
 	}
+	my $n_cols = $check_forks ? 6 : 5;
 	my $alternate = 1;
 	for (my $i = $from; $i <= $to; $i++) {
 		my $pr = $projects[$i];
+
+                if ($use_sections) {
+			if (print_section($order, $n_cols, $i, \@projects)) {
+				$alternate = 1;
+			}
+                }
+
 		if ($alternate) {
 			print "<tr class=\"dark\">\n";
 		} else {
-- 
1.5.5.2
Previous: Gustavo Sverzut BarbieriNext: Gustavo Sverzut Barbieri
Message 3 of 8 in “gitweb use sections”
  1. 0/2 gitweb use sectionsGustavo Sverzut Barbieri, Jul 29, 2008
  2. 1/2 gitweb: sort projects by path.Gustavo Sverzut Barbieri, Jul 29, 2008
  3. 2/2 gitweb: add section support to gitweb project listing.Gustavo Sverzut Barbieri, Jul 29, 2008
  4. 1/2 gitweb: sort projects by path.Gustavo Sverzut Barbieri, Jul 29, 2008
  5. Gustavo Sverzut BarbieriJul 31, 2008
  6. Petr BaudisJul 31, 2008
  7. Gustavo Sverzut BarbieriJul 31, 2008
  8. Gustavo Sverzut BarbieriAug 10, 2008

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.