From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastien Cevey Subject: [PATCH] Optional grouping of projects by category. Date: Sun, 27 Jul 2008 02:36:58 +0200 Message-ID: <8763qsi2mt.wl%seb@cine7.net> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Sun Jul 27 02:45:40 2008 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1KMuOJ-00070P-7C for gcvg-git-2@gmane.org; Sun, 27 Jul 2008 02:45:39 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756199AbYG0Aog (ORCPT ); Sat, 26 Jul 2008 20:44:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756214AbYG0Aog (ORCPT ); Sat, 26 Jul 2008 20:44:36 -0400 Received: from smtp.nimag.net ([62.220.136.11]:39502 "EHLO smtp.nimag.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754447AbYG0Aof (ORCPT ); Sat, 26 Jul 2008 20:44:35 -0400 X-Greylist: delayed 474 seconds by postgrey-1.27 at vger.kernel.org; Sat, 26 Jul 2008 20:44:35 EDT Received: from crookshanks.cine7.net (85-218-46-38.dclient.lsne.ch [85.218.46.38]) by smtp.nimag.net (Postfix) with ESMTP id B6D03CB0985; Sun, 27 Jul 2008 02:36:38 +0200 (CEST) User-Agent: Wanderlust/2.14.0 (Africa) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: This adds the GITWEB_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. The feature is inspired from Sham Chukoury's patch for the XMMS2 gitweb, but has been rewritten for the current gitweb development HEAD. Thanks to Florian Ragwitz for Perl tips. Signed-off-by: Sebastien Cevey --- We used to run a modified gitweb for XMMS2 Git repositories which, among other things, grouped projects by categories. The feature was lost when we caught up with upstream gitweb, but I've rehacked this feature back on top of the current HEAD. I assume this might be a wanted feature, or at least it was in Jakub's old wishlist he posted on 2006-06-21 02:51:18. Feedback on the idea and implementation are welcome. Makefile | 2 + gitweb/README | 11 ++++ gitweb/gitweb.css | 5 ++ gitweb/gitweb.perl | 129 ++++++++++++++++++++++++++++++++++++++-------------- 4 files changed, 112 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 798a2f2..2309260 100644 --- a/Makefile +++ b/Makefile @@ -208,6 +208,7 @@ GITWEB_EXPORT_OK = GITWEB_STRICT_EXPORT = GITWEB_BASE_URL = GITWEB_LIST = +GITWEB_GROUP_CATEGORIES = GITWEB_HOMETEXT = indextext.html GITWEB_CSS = gitweb.css GITWEB_LOGO = git-logo.png @@ -1145,6 +1146,7 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl -e 's|++GITWEB_STRICT_EXPORT++|$(GITWEB_STRICT_EXPORT)|g' \ -e 's|++GITWEB_BASE_URL++|$(GITWEB_BASE_URL)|g' \ -e 's|++GITWEB_LIST++|$(GITWEB_LIST)|g' \ + -e 's|++GITWEB_GROUP_CATEGORIES++|$(GITWEB_GROUP_CATEGORIES)|g' \ -e 's|++GITWEB_HOMETEXT++|$(GITWEB_HOMETEXT)|g' \ -e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \ -e 's|++GITWEB_LOGO++|$(GITWEB_LOGO)|g' \ diff --git a/gitweb/README b/gitweb/README index 6908036..2b77c20 100644 --- a/gitweb/README +++ b/gitweb/README @@ -38,6 +38,11 @@ You can specify the following configuration variables when building GIT: using gitweb" in INSTALL file for gitweb to find out how to generate such file from scan of a directory. [No default, which means use root directory for projects] + * GITWEB_GROUP_CATEGORIES + Groups projects by category on the main projects list page if set + to true. The category of a project is determined by the + $GIT_DIR/category file or the 'category' variable in its + configuration file. [No default / Not set] * GITWEB_EXPORT_OK Show repository only if this file exists (in repository). Only effective if this variable evaluates to true. [No default / Not set] @@ -188,6 +193,12 @@ 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. + * $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". diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css index aa0eeca..7f1e2cc 100644 --- a/gitweb/gitweb.css +++ b/gitweb/gitweb.css @@ -264,6 +264,11 @@ td.current_head { text-decoration: underline; } +td.category { + padding-top: 1em; + font-weight: bold; +} + table.diff_tree span.file_status.new { color: #008000; } diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 90cd99b..fe8ae72 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -78,6 +78,13 @@ 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 +our $projects_list_group_categories = "++GITWEB_GROUP_CATEGORIES++"; + +# 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"; @@ -1710,18 +1717,28 @@ sub git_get_path_by_hash { ## ...................................................................... ## git utility functions, directly accessing git repository -sub git_get_project_description { - my $path = shift; +sub git_get_project_config_from_file { + my ($name, $path) = @_; $git_dir = "$projectroot/$path"; - open my $fd, "$git_dir/description" - or return git_get_project_config('description'); - my $descr = <$fd>; + open my $fd, "<", "$git_dir/$name" + or return git_get_project_config($name); + my $conf = <$fd>; close $fd; - if (defined $descr) { - chomp $descr; + if (defined $conf) { + chomp $conf; } - return $descr; + return $conf; +} + +sub git_get_project_description { + my $path = shift; + return git_get_project_config_from_file('description', $path); +} + +sub git_get_project_category { + my $path = shift; + return git_get_project_config_from_file('category', $path); } sub git_get_project_url_list { @@ -3535,8 +3552,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) = @_; @@ -3558,6 +3576,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->{'cat'}) { + my $cat = git_get_project_category($pr->{'path'}) || + $project_list_default_category; + $pr->{'cat'} = to_utf8($cat); + } if ($check_forks) { my $pname = $pr->{'path'}; if (($pname =~ s/\.git$//) && @@ -3574,6 +3597,17 @@ sub fill_project_list_info { return @projects; } +sub build_sorted_category_list { + my ($projlist) = @_; + my %categories; + + for my $pr (@{ $projlist }) { + push @{$categories{ $pr->{'cat'} }}, $pr; + } + + return %categories; +} + # print 'sort by' element, either sorting by $key if $name eq $order # (changing $list), or generating 'sort by $name' replay link otherwise sub print_sort_th { @@ -3604,36 +3638,15 @@ sub print_sort_th_num { print_sort_th(0, @_); } -sub git_project_list_body { - my ($projlist, $order, $from, $to, $extra, $no_header) = @_; - - my ($check_forks) = gitweb_check_feature('forks'); - my @projects = fill_project_list_info($projlist, $check_forks); +sub print_project_rows { + my ($projects, $from, $to, $check_forks) = @_; - $order ||= $default_projects_order; $from = 0 unless defined $from; - $to = $#projects if (!defined $to || $#projects < $to); + $to = $#$projects if (!defined $to || $#$projects < $to); - print "\n"; - unless ($no_header) { - print "\n"; - if ($check_forks) { - print "\n"; - } - print_sort_th_str('project', $order, 'path', - 'Project', \@projects); - print_sort_th_str('descr', $order, 'descr_long', - 'Description', \@projects); - print_sort_th_str('owner', $order, 'owner', - 'Owner', \@projects); - print_sort_th_num('age', $order, 'age', - 'Last Change', \@projects); - print "\n" . # for links - "\n"; - } my $alternate = 1; for (my $i = $from; $i <= $to; $i++) { - my $pr = $projects[$i]; + my $pr = $projects->[$i]; if ($alternate) { print "\n"; } else { @@ -3665,6 +3678,52 @@ sub git_project_list_body { "\n" . "\n"; } +} + +sub git_project_list_body { + my ($projlist, $order, $from, $to, $extra, $no_header) = @_; + + my ($check_forks) = gitweb_check_feature('forks'); + my @all_projects = fill_project_list_info($projlist, $check_forks); + + $order ||= $default_projects_order; + + print "
\n"; + unless ($no_header) { + print "\n"; + if ($check_forks) { + print "\n"; + } + print_sort_th_str('project', $order, 'path', + 'Project', \@all_projects); + print_sort_th_str('descr', $order, 'descr_long', + 'Description', \@all_projects); + print_sort_th_str('owner', $order, 'owner', + 'Owner', \@all_projects); + print_sort_th_num('age', $order, 'age', + 'Last Change', \@all_projects); + print "\n" . # for links + "\n"; + } + + if ($projects_list_group_categories) { + my %categories = build_sorted_category_list(\@all_projects); + foreach my $cat (sort keys %categories) { + unless ($cat eq "") { + print "\n"; + if ($check_forks) { + print "\n"; + } + print "\n"; + print "\n"; + } + + print_project_rows($categories{$cat}, $from, $to, $check_forks); + } + } else { + print_project_rows(\@all_projects, $from, $to, $check_forks); + } + if (defined $extra) { print "\n"; if ($check_forks) { -- 1.5.3.7
" . $cat . "