From: "Sébastien Cevey" <seb@cine7.net>
To: git@vger.kernel.org
Cc: Jakub Narebski <jnareb@gmail.com>,
Junio C Hamano <gitster@pobox.com>, Petr Baudis <pasky@suse.cz>,
Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
Subject: [PATCH v3 3/3] gitweb: Optional grouping of projects by category
Date: Thu, 04 Dec 2008 01:46:40 +0100 [thread overview]
Message-ID: <87hc5k22dr.wl%seb@cine7.net> (raw)
In-Reply-To: <87iqq022gz.wl%seb@cine7.net>
This adds the $projects_list_group_categories option which, if enabled,
will result in grouping projects by category on the project list page.
The category is specified for each project by the $GIT_DIR/category file
or the 'category' variable in its configuration file. By default, projects
are put in the $project_list_default_category category.
Note:
- Categories are always sorted alphabetically, with projects in
each category sorted according to the globally selected $order.
- When displaying a subset of all the projects (page limiting), the
category headers are only displayed for projects present on the page.
The feature is inspired from Sham Chukoury's patch for the XMMS2
gitweb, but has been rewritten for the current gitweb development
HEAD. The CSS for categories is inspired from Gustavo Sverzut Barbieri's
patch to group projects by path.
Thanks to Florian Ragwitz for Perl tips.
Signed-off-by: Sebastien Cevey <seb@cine7.net>
---
Cleaner patch this time indeed. Still no fancy sorting of categories,
only alphabetical.
gitweb/README | 16 ++++++++++++
gitweb/gitweb.css | 7 +++++
gitweb/gitweb.perl | 67 +++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 87 insertions(+), 3 deletions(-)
diff --git a/gitweb/README b/gitweb/README
index 825162a..f8f8872 100644
--- a/gitweb/README
+++ b/gitweb/README
@@ -188,6 +188,15 @@ not include variables usually directly set during build):
full description is available as 'title' attribute (usually shown on
mouseover). By default set to 25, which might be too small if you
use long project descriptions.
+ * $projects_list_group_categories
+ Enables the grouping of projects by category on the project list page.
+ The category of a project is determined by the $GIT_DIR/category
+ file or the 'gitweb.category' variable in its repository configuration.
+ Disabled by default.
+ * $project_list_default_category
+ Default category for projects for which none is specified. If set
+ to the empty string, such projects will remain uncategorized and
+ listed at the top, above categorized projects.
* @git_base_url_list
List of git base URLs used for URL to where fetch project from, shown
in project summary page. Full URL is "$git_base_url/$project".
@@ -269,6 +278,13 @@ You can use the following files in repository:
from the template during repository creation. You can use the
gitweb.description repo configuration variable, but the file takes
precedence.
+ * category (or gitweb.category)
+ Singe line category of a project, used to group projects if
+ $projects_list_group_categories is enabled. By default (file and
+ configuration variable absent), uncategorized projects are put in
+ the $project_list_default_category category. You can use the
+ gitweb.category repo configuration variable, but the file takes
+ precedence.
* cloneurl (or multiple-valued gitweb.url)
File with repository URL (used for clone and fetch), one per line.
Displayed in the project summary page. You can use multiple-valued
diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css
index a01eac8..64f2a41 100644
--- a/gitweb/gitweb.css
+++ b/gitweb/gitweb.css
@@ -264,6 +264,13 @@ td.current_head {
text-decoration: underline;
}
+td.category {
+ background-color: #d9d8d1;
+ border-top: 1px solid #000000;
+ border-left: 1px solid #000000;
+ font-weight: bold;
+}
+
table.diff_tree span.file_status.new {
color: #008000;
}
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index a6bb702..97a9b73 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -87,6 +87,14 @@ our $projects_list = "++GITWEB_LIST++";
# the width (in characters) of the projects list "Description" column
our $projects_list_description_width = 25;
+# group projects by category on the projects list
+# (enabled if this variable evaluates to true)
+our $projects_list_group_categories = 0;
+
+# default category if none specified
+# (leave the empty string for no category)
+our $project_list_default_category = "";
+
# default order of projects list
# valid values are none, project, descr, owner, and age
our $default_projects_order = "project";
@@ -2023,6 +2031,11 @@ sub git_get_project_description {
return git_get_file_or_project_config('description', $path);
}
+sub git_get_project_category {
+ my $path = shift;
+ return git_get_file_or_project_config('category', $path);
+}
+
sub git_get_project_ctags {
my $path = shift;
my $ctags = {};
@@ -3915,8 +3928,9 @@ sub git_patchset_body {
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
-# fills project list info (age, description, owner, forks) for each
-# project in the list, removing invalid projects from returned list
+# fills project list info (age, description, owner, category, forks)
+# for each project in the list, removing invalid projects from
+# returned list
# NOTE: modifies $projlist, but does not remove entries from it
sub fill_project_list_info {
my ($projlist, $check_forks) = @_;
@@ -3939,6 +3953,11 @@ sub fill_project_list_info {
if (!defined $pr->{'owner'}) {
$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
}
+ if ($projects_list_group_categories && !defined $pr->{'category'}) {
+ my $cat = git_get_project_category($pr->{'path'}) ||
+ $project_list_default_category;
+ $pr->{'category'} = to_utf8($cat);
+ }
if ($check_forks) {
my $pname = $pr->{'path'};
if (($pname =~ s/\.git$//) &&
@@ -3956,6 +3975,19 @@ sub fill_project_list_info {
return @projects;
}
+# returns a hash of categories, containing the list of project
+# belonging to each category
+sub build_projlist_by_category {
+ my $projlist = shift;
+ my %categories;
+
+ for my $pr (@$projlist) {
+ push @{$categories{ $pr->{'category'} }}, $pr;
+ }
+
+ return %categories;
+}
+
# print 'sort by' <th> element, generating 'sort by $name' replay link
# if that order is not selected
sub print_sort_th {
@@ -4077,7 +4109,36 @@ sub git_project_list_body {
"</tr>\n";
}
- print_project_rows(\@projects, $from, $to, $check_forks, $show_ctags);
+ if ($projects_list_group_categories) {
+ # only display categories with projects in the $from-$to window
+ my %categories = build_projlist_by_category(\@projects);
+ foreach my $cat (sort keys %categories) {
+ my $num_cats = @{$categories{$cat}};
+
+ # out of the window to display, done
+ last if defined $to and $to < 0;
+
+ # in the window to display
+ if (!defined $from or $from < $num_cats) {
+ unless ($cat eq "") {
+ print "<tr>\n";
+ if ($check_forks) {
+ print "<td></td>\n";
+ }
+ print "<td class=\"category\" colspan=\"5\">$cat</td>\n";
+ print "</tr>\n";
+ }
+
+ print_project_rows($categories{$cat}, $from, $to, $check_forks, $show_ctags);
+ }
+
+ # adjust $from/$to offset, keep $from positive
+ $from = ($from > $num_cats) ? $from - $num_cats : 0 if defined $from;
+ $to -= $num_cats if defined $to;
+ }
+ } else {
+ print_project_rows(\@projects, $from, $to, $check_forks, $show_ctags);
+ }
if (defined $extra) {
print "<tr>\n";
--
1.5.6.5
next prev parent reply other threads:[~2008-12-04 0:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-02 15:04 [PATCH] gitweb: Optional grouping of projects by category Sebastien Cevey
2008-12-02 23:36 ` Jakub Narebski
2008-12-03 14:22 ` [PATCH v2] " Sébastien Cevey
2008-12-03 22:51 ` Junio C Hamano
2008-12-03 23:12 ` Jakub Narebski
2008-12-04 0:39 ` [PATCH v3 0/3] " Sébastien Cevey
2008-12-04 0:43 ` Junio C Hamano
2008-12-04 0:42 ` [PATCH v3 1/3] gitweb: Modularized git_get_project_description to be more generic Sébastien Cevey
2008-12-04 0:44 ` [PATCH v3 2/3] gitweb: Split git_project_list_body in two functions Sébastien Cevey
2008-12-04 0:46 ` Sébastien Cevey [this message]
2008-12-04 19:37 ` [PATCH v3 3/3] gitweb: Optional grouping of projects by category Junio C Hamano
2008-12-05 2:08 ` Jakub Narebski
2008-12-05 2:32 ` Sébastien Cevey
2008-12-05 10:45 ` Jakub Narebski
2008-12-11 23:34 ` Sébastien Cevey
2008-12-12 0:13 ` Jakub Narebski
2008-12-12 0:40 ` Sébastien Cevey
2008-12-12 2:03 ` Jakub Narebski
2008-12-12 3:10 ` Sébastien Cevey
2008-12-12 9:26 ` Jakub Narebski
2008-12-05 1:52 ` [PATCH v3 2/3] gitweb: Split git_project_list_body in two functions Jakub Narebski
2008-12-05 1:38 ` [PATCH v3 1/3] gitweb: Modularized git_get_project_description to be more generic Jakub Narebski
2008-12-03 14:29 ` [PATCH] gitweb: Optional grouping of projects by category Sébastien Cevey
2008-12-03 21:14 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87hc5k22dr.wl%seb@cine7.net \
--to=seb@cine7.net \
--cc=barbieri@profusion.mobi \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
--cc=pasky@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.