{"thread":{"id":"14696","subject":"[PATCH] Optional grouping of projects by category.","startedAt":"2008-07-27T00:36:58Z","lastAt":"2008-09-05T12:06:22Z","messageCount":4,"participants":["Sebastien Cevey","Jakub Narebski","Sébastien Cevey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"85129","messageId":"8763qsi2mt.wl%seb@cine7.net","threadId":"14696","inReplyTo":null,"subject":"[PATCH] Optional grouping of projects by category.","fromName":"Sebastien Cevey","fromEmail":"seb@cine7.net","sentAt":"2008-07-27T00:36:58Z","receivedAt":"2008-07-27T00:36:58Z","isPatch":true,"sender":{"key":"seb@cine7.net","avatar":"https://avatars.githubusercontent.com/u/36964?v=4"},"body":"This adds the GITWEB_GROUP_CATEGORIES option which, if enabled, will\nresult in grouping projects by category on the project list page.  The\ncategory is specified for each project by the $GIT_DIR/category file\nor the 'category' variable in its configuration file.\n\nThe feature is inspired from Sham Chukoury's patch for the XMMS2\ngitweb, but has been rewritten for the current gitweb development\nHEAD.\n\nThanks to Florian Ragwitz for Perl tips.\n\nSigned-off-by: Sebastien Cevey <seb@cine7.net>\n---\n\nWe used to run a modified gitweb for XMMS2 Git repositories which,\namong other things, grouped projects by categories.  The feature was\nlost when we caught up with upstream gitweb, but I've rehacked this\nfeature back on top of the current HEAD.\n\nI assume this might be a wanted feature, or at least it was in Jakub's\nold wishlist he posted on 2006-06-21 02:51:18.\n\nFeedback on the idea and implementation are welcome.\n\n Makefile           |    2 +\n gitweb/README      |   11 ++++\n gitweb/gitweb.css  |    5 ++\n gitweb/gitweb.perl |  129 ++++++++++++++++++++++++++++++++++++++--------------\n 4 files changed, 112 insertions(+), 35 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 798a2f2..2309260 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -208,6 +208,7 @@ GITWEB_EXPORT_OK =\n GITWEB_STRICT_EXPORT =\n GITWEB_BASE_URL =\n GITWEB_LIST =\n+GITWEB_GROUP_CATEGORIES =\n GITWEB_HOMETEXT = indextext.html\n GITWEB_CSS = gitweb.css\n GITWEB_LOGO = git-logo.png\n@@ -1145,6 +1146,7 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl\n \t    -e 's|++GITWEB_STRICT_EXPORT++|$(GITWEB_STRICT_EXPORT)|g' \\\n \t    -e 's|++GITWEB_BASE_URL++|$(GITWEB_BASE_URL)|g' \\\n \t    -e 's|++GITWEB_LIST++|$(GITWEB_LIST)|g' \\\n+\t    -e 's|++GITWEB_GROUP_CATEGORIES++|$(GITWEB_GROUP_CATEGORIES)|g' \\\n \t    -e 's|++GITWEB_HOMETEXT++|$(GITWEB_HOMETEXT)|g' \\\n \t    -e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \\\n \t    -e 's|++GITWEB_LOGO++|$(GITWEB_LOGO)|g' \\\ndiff --git a/gitweb/README b/gitweb/README\nindex 6908036..2b77c20 100644\n--- a/gitweb/README\n+++ b/gitweb/README\n@@ -38,6 +38,11 @@ You can specify the following configuration variables when building GIT:\n    using gitweb\" in INSTALL file for gitweb to find out how to generate\n    such file from scan of a directory. [No default, which means use root\n    directory for projects]\n+ * GITWEB_GROUP_CATEGORIES\n+   Groups projects by category on the main projects list page if set\n+   to true.  The category of a project is determined by the\n+   $GIT_DIR/category file or the 'category' variable in its\n+   configuration file.  [No default / Not set]\n  * GITWEB_EXPORT_OK\n    Show repository only if this file exists (in repository).  Only\n    effective if this variable evaluates to true.  [No default / Not set]\n@@ -188,6 +193,12 @@ not include variables usually directly set during build):\n    full description is available as 'title' attribute (usually shown on\n    mouseover).  By default set to 25, which might be too small if you\n    use long project descriptions.\n+ * $projects_list_group_categories\n+   Enables the grouping of projects by category on the project list page.\n+ * $project_list_default_category\n+   Default category for projects for which none is specified.  If set\n+   to the empty string, such projects will remain uncategorized and\n+   listed at the top, above categorized projects.\n  * @git_base_url_list\n    List of git base URLs used for URL to where fetch project from, shown\n    in project summary page.  Full URL is \"$git_base_url/$project\".\ndiff --git a/gitweb/gitweb.css b/gitweb/gitweb.css\nindex aa0eeca..7f1e2cc 100644\n--- a/gitweb/gitweb.css\n+++ b/gitweb/gitweb.css\n@@ -264,6 +264,11 @@ td.current_head {\n \ttext-decoration: underline;\n }\n \n+td.category {\n+\tpadding-top: 1em;\n+\tfont-weight: bold;\n+}\n+\n table.diff_tree span.file_status.new {\n \tcolor: #008000;\n }\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 90cd99b..fe8ae72 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -78,6 +78,13 @@ our $projects_list = \"++GITWEB_LIST++\";\n # the width (in characters) of the projects list \"Description\" column\n our $projects_list_description_width = 25;\n \n+# group projects by category on the projects list\n+our $projects_list_group_categories = \"++GITWEB_GROUP_CATEGORIES++\";\n+\n+# default category if none specified\n+# (leave the empty string for no category)\n+our $project_list_default_category = \"\";\n+\n # default order of projects list\n # valid values are none, project, descr, owner, and age\n our $default_projects_order = \"project\";\n@@ -1710,18 +1717,28 @@ sub git_get_path_by_hash {\n ## ......................................................................\n ## git utility functions, directly accessing git repository\n \n-sub git_get_project_description {\n-\tmy $path = shift;\n+sub git_get_project_config_from_file {\n+\tmy ($name, $path) = @_;\n \n \t$git_dir = \"$projectroot/$path\";\n-\topen my $fd, \"$git_dir/description\"\n-\t\tor return git_get_project_config('description');\n-\tmy $descr = <$fd>;\n+\topen my $fd, \"<\", \"$git_dir/$name\"\n+\t\tor return git_get_project_config($name);\n+\tmy $conf = <$fd>;\n \tclose $fd;\n-\tif (defined $descr) {\n-\t\tchomp $descr;\n+\tif (defined $conf) {\n+\t\tchomp $conf;\n \t}\n-\treturn $descr;\n+\treturn $conf;\n+}\n+\n+sub git_get_project_description {\n+\tmy $path = shift;\n+\treturn git_get_project_config_from_file('description', $path);\n+}\n+\n+sub git_get_project_category {\n+\tmy $path = shift;\n+\treturn git_get_project_config_from_file('category', $path);\n }\n \n sub git_get_project_url_list {\n@@ -3535,8 +3552,9 @@ sub git_patchset_body {\n \n # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n \n-# fills project list info (age, description, owner, forks) for each\n-# project in the list, removing invalid projects from returned list\n+# fills project list info (age, description, owner, category, forks)\n+# for each project in the list, removing invalid projects from\n+# returned list\n # NOTE: modifies $projlist, but does not remove entries from it\n sub fill_project_list_info {\n \tmy ($projlist, $check_forks) = @_;\n@@ -3558,6 +3576,11 @@ sub fill_project_list_info {\n \t\tif (!defined $pr->{'owner'}) {\n \t\t\t$pr->{'owner'} = git_get_project_owner(\"$pr->{'path'}\") || \"\";\n \t\t}\n+\t\tif ($projects_list_group_categories && !defined $pr->{'cat'}) {\n+\t\t\tmy $cat = git_get_project_category($pr->{'path'}) ||\n+\t\t\t                                   $project_list_default_category;\n+\t\t\t$pr->{'cat'} = to_utf8($cat);\n+\t\t}\n \t\tif ($check_forks) {\n \t\t\tmy $pname = $pr->{'path'};\n \t\t\tif (($pname =~ s/\\.git$//) &&\n@@ -3574,6 +3597,17 @@ sub fill_project_list_info {\n \treturn @projects;\n }\n \n+sub build_sorted_category_list {\n+\tmy ($projlist) = @_;\n+\tmy %categories;\n+\n+\tfor my $pr (@{ $projlist }) {\n+\t\tpush @{$categories{ $pr->{'cat'} }}, $pr;\n+\t}\n+\n+\treturn %categories;\n+}\n+\n # print 'sort by' <th> element, either sorting by $key if $name eq $order\n # (changing $list), or generating 'sort by $name' replay link otherwise\n sub print_sort_th {\n@@ -3604,36 +3638,15 @@ sub print_sort_th_num {\n \tprint_sort_th(0, @_);\n }\n \n-sub git_project_list_body {\n-\tmy ($projlist, $order, $from, $to, $extra, $no_header) = @_;\n-\n-\tmy ($check_forks) = gitweb_check_feature('forks');\n-\tmy @projects = fill_project_list_info($projlist, $check_forks);\n+sub print_project_rows {\n+\tmy ($projects, $from, $to, $check_forks) = @_;\n \n-\t$order ||= $default_projects_order;\n \t$from = 0 unless defined $from;\n-\t$to = $#projects if (!defined $to || $#projects < $to);\n+\t$to = $#$projects if (!defined $to || $#$projects < $to);\n \n-\tprint \"<table class=\\\"project_list\\\">\\n\";\n-\tunless ($no_header) {\n-\t\tprint \"<tr>\\n\";\n-\t\tif ($check_forks) {\n-\t\t\tprint \"<th></th>\\n\";\n-\t\t}\n-\t\tprint_sort_th_str('project', $order, 'path',\n-\t\t                  'Project', \\@projects);\n-\t\tprint_sort_th_str('descr', $order, 'descr_long',\n-\t\t                  'Description', \\@projects);\n-\t\tprint_sort_th_str('owner', $order, 'owner',\n-\t\t                  'Owner', \\@projects);\n-\t\tprint_sort_th_num('age', $order, 'age',\n-\t\t                  'Last Change', \\@projects);\n-\t\tprint \"<th></th>\\n\" . # for links\n-\t\t      \"</tr>\\n\";\n-\t}\n \tmy $alternate = 1;\n \tfor (my $i = $from; $i <= $to; $i++) {\n-\t\tmy $pr = $projects[$i];\n+\t\tmy $pr = $projects->[$i];\n \t\tif ($alternate) {\n \t\t\tprint \"<tr class=\\\"dark\\\">\\n\";\n \t\t} else {\n@@ -3665,6 +3678,52 @@ sub git_project_list_body {\n \t\t      \"</td>\\n\" .\n \t\t      \"</tr>\\n\";\n \t}\n+}\n+\n+sub git_project_list_body {\n+\tmy ($projlist, $order, $from, $to, $extra, $no_header) = @_;\n+\n+\tmy ($check_forks) = gitweb_check_feature('forks');\n+\tmy @all_projects = fill_project_list_info($projlist, $check_forks);\n+\n+\t$order ||= $default_projects_order;\n+\n+\tprint \"<table class=\\\"project_list\\\">\\n\";\n+\tunless ($no_header) {\n+\t\tprint \"<tr>\\n\";\n+\t\tif ($check_forks) {\n+\t\t\tprint \"<th></th>\\n\";\n+\t\t}\n+\t\tprint_sort_th_str('project', $order, 'path',\n+\t\t                  'Project', \\@all_projects);\n+\t\tprint_sort_th_str('descr', $order, 'descr_long',\n+\t\t                  'Description', \\@all_projects);\n+\t\tprint_sort_th_str('owner', $order, 'owner',\n+\t\t                  'Owner', \\@all_projects);\n+\t\tprint_sort_th_num('age', $order, 'age',\n+\t\t                  'Last Change', \\@all_projects);\n+\t\tprint \"<th></th>\\n\" . # for links\n+\t\t      \"</tr>\\n\";\n+\t}\n+\n+\tif ($projects_list_group_categories) {\n+\t\tmy %categories = build_sorted_category_list(\\@all_projects);\n+\t\tforeach my $cat (sort keys %categories) {\n+\t\t\tunless ($cat eq \"\") {\n+\t\t\t\tprint \"<tr>\\n\";\n+\t\t\t\tif ($check_forks) {\n+\t\t\t\t\tprint \"<td></td>\\n\";\n+\t\t\t\t}\n+\t\t\t\tprint \"<td class=\\\"category\\\" colspan=\\\"5\\\">\" . $cat . \"</td>\\n\";\n+\t\t\t\tprint \"</tr>\\n\";\n+\t\t\t}\n+\n+\t\t\tprint_project_rows($categories{$cat}, $from, $to, $check_forks);\n+\t\t}\n+\t} else {\n+\t\tprint_project_rows(\\@all_projects, $from, $to, $check_forks);\n+\t}\n+\n \tif (defined $extra) {\n \t\tprint \"<tr>\\n\";\n \t\tif ($check_forks) {\n-- \n1.5.3.7\n"},{"id":"85160","messageId":"m3zlo3u2r2.fsf@localhost.localdomain","threadId":"14696","inReplyTo":"8763qsi2mt.wl%seb@cine7.net","subject":"Re: [PATCH] Optional grouping of projects by category.","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-07-27T08:53:43Z","receivedAt":"2008-07-27T08:53:43Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Sebastien Cevey <seb@cine7.net> writes:\n\n> This adds the GITWEB_GROUP_CATEGORIES option which, if enabled, will\n> result in grouping projects by category on the project list page.  The\n> category is specified for each project by the $GIT_DIR/category file\n> or the 'category' variable in its configuration file.\n> \n> The feature is inspired from Sham Chukoury's patch for the XMMS2\n> gitweb, but has been rewritten for the current gitweb development\n> HEAD.\n> \n> Thanks to Florian Ragwitz for Perl tips.\n\nThanks a lot.  I don't know if it is a good time, with git being in\nfeature freeze, and GSoC project about adding caching to gitweb in the\nworks, but I'll take this patch and resend it if needed.  I'll try to\ncomment on it soon.\n\nThat said, I think that the subject (oneline commit summary) should\ninclude 'gitweb', e.g.\n\n  \"gitweb: Optional grouping of projects by category\"\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"85310","messageId":"874p69j38j.wl%seb@cine7.net","threadId":"14696","inReplyTo":"m3zlo3u2r2.fsf@localhost.localdomain","subject":"Re: [PATCH] Optional grouping of projects by category.","fromName":"Sébastien Cevey","fromEmail":"seb@cine7.net","sentAt":"2008-07-28T18:03:08Z","receivedAt":"2008-07-28T18:03:08Z","isPatch":true,"sender":{"key":"seb@cine7.net","avatar":"https://avatars.githubusercontent.com/u/36964?v=4"},"body":"At Sun, 27 Jul 2008 01:53:43 -0700 (PDT), Jakub Narebski wrote:\n\n> Thanks a lot.  I don't know if it is a good time, with git being in\n> feature freeze, and GSoC project about adding caching to gitweb in\n> the works, but I'll take this patch and resend it if needed.  I'll\n> try to comment on it soon.\n\nGreat, looking forward to that, thanks!\n\n-- \nSébastien Cevey / inso.cc\n"},{"id":"89840","messageId":"87tzcuyeyp.wl%seb@cine7.net","threadId":"14696","inReplyTo":"m3zlo3u2r2.fsf@localhost.localdomain","subject":"Re: [PATCH] Optional grouping of projects by category.","fromName":"Sébastien Cevey","fromEmail":"seb@cine7.net","sentAt":"2008-09-05T12:06:22Z","receivedAt":"2008-09-05T12:06:22Z","isPatch":true,"sender":{"key":"seb@cine7.net","avatar":"https://avatars.githubusercontent.com/u/36964?v=4"},"body":"At Sun, 27 Jul 2008 01:53:43 -0700 (PDT), Jakub Narebski wrote:\n\nHello,\n\n> Thanks a lot.  I don't know if it is a good time, with git being in\n> feature freeze, and GSoC project about adding caching to gitweb in\n> the works, but I'll take this patch and resend it if needed.\n\nI just saw a gitweb feature patch was merged three days ago, so I was\nwondering if the feature freeze is over?  I wanted to ping you and ask\nif you want me to resend the patch, or if you had time to take a look\nat it?\n\nThanks!\n\n-- \nSébastien Cevey / inso.cc\n"}]}