{"thread":{"id":"17649","subject":"[PATCHv3 2/3 (resend)] gitweb: Split git_project_list_body in two functions","startedAt":"2008-12-03T23:33:27Z","lastAt":"2008-12-03T23:45:04Z","messageCount":2,"participants":["Sebastien Cevey"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"103725","messageId":"87wsc1p51r.wl%seb@cine7.net","threadId":"17649","inReplyTo":"87y6whp56g.wl%seb@cine7.net","subject":"[PATCHv3 3/3 (resend)] gitweb: Optional grouping of projects by category","fromName":"Sebastien Cevey","fromEmail":"seb@cine7.net","sentAt":"2008-12-03T23:33:27Z","receivedAt":"2008-12-03T23:33:27Z","isPatch":false,"sender":{"key":"seb@cine7.net","avatar":"https://avatars.githubusercontent.com/u/36964?v=4"},"body":"This adds the $projects_list_group_categories option which, if enabled,\nwill result in grouping projects by category on the project list page.\nThe category is specified for each project by the $GIT_DIR/category file\nor the 'category' variable in its configuration file. By default, projects\nare put in the $project_list_default_category category.\n\nNote:\n- Categories are always sorted alphabetically, with projects in\n  each category sorted according to the globally selected $order.\n- When displaying a subset of all the projects (page limiting), the\n  category headers are only displayed for projects present on the page.\n\nThe feature is inspired from Sham Chukoury's patch for the XMMS2\ngitweb, but has been rewritten for the current gitweb development\nHEAD. The CSS for categories is inspired from Gustavo Sverzut Barbieri's\npatch to group projects by path.\n\nThanks to Florian Ragwitz for Perl tips.\n\nSigned-off-by: Sebastien Cevey <seb@cine7.net>\n---\n gitweb/README      |   16 +++++++++++++\n gitweb/gitweb.css  |    7 ++++++\n gitweb/gitweb.perl |   60 +++++++++++++++++++++++++++++++++++++++++++++++++--\n 3 files changed, 80 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/README b/gitweb/README\nindex a9dc2e5..7d4bfe9 100644\n--- a/gitweb/README\n+++ b/gitweb/README\n@@ -186,6 +186,15 @@ 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+   The category of a project is determined by the $GIT_DIR/category\n+   file or the 'gitweb.category' variable in its repository configuration.\n+   Disabled by default.\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\".\n@@ -267,6 +276,13 @@ You can use the following files in repository:\n    from the template during repository creation. You can use the\n    gitweb.description repo configuration variable, but the file takes\n    precedence.\n+ * category (or gitweb.category)\n+   Singe line category of a project, used to group projects if\n+   $projects_list_group_categories is enabled. By default (file and\n+   configuration variable absent), uncategorized projects are put in\n+   the $project_list_default_category category. You can use the\n+   gitweb.category repo configuration variable, but the file takes\n+   precedence.\n  * cloneurl (or multiple-valued gitweb.url)\n    File with repository URL (used for clone and fetch), one per line.\n    Displayed in the project summary page. You can use multiple-valued\ndiff --git a/gitweb/gitweb.css b/gitweb/gitweb.css\nindex a01eac8..64f2a41 100644\n--- a/gitweb/gitweb.css\n+++ b/gitweb/gitweb.css\n@@ -264,6 +264,13 @@ td.current_head {\n \ttext-decoration: underline;\n }\n \n+td.category {\n+\tbackground-color: #d9d8d1;\n+\tborder-top: 1px solid #000000;\n+\tborder-left: 1px solid #000000;\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 380c702..dcfc495 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -87,6 +87,14 @@ 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+# (enabled if this variable evaluates to true)\n+our $projects_list_group_categories = 0;\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@@ -2046,6 +2054,11 @@ sub git_get_project_description {\n \treturn git_get_file_or_project_config('description', $path);\n }\n \n+sub git_get_project_category {\n+\tmy $path = shift;\n+\treturn git_get_file_or_project_config('category', $path);\n+}\n+\n sub git_get_project_ctags {\n \tmy $path = shift;\n \tmy $ctags = {};\n@@ -3949,8 +3962,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@@ -3973,6 +3987,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->{'category'}) {\n+\t\t\tmy $cat = git_get_project_category($pr->{'path'}) ||\n+\t\t\t                                   $project_list_default_category;\n+\t\t\t$pr->{'category'} = 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@@ -3990,6 +4009,23 @@ sub fill_project_list_info {\n \treturn @projects;\n }\n \n+# returns a hash of categories, containing the list of project\n+# belonging to each category\n+sub build_projlist_by_category {\n+\tmy ($projlist, $from, $to) = @_;\n+\tmy %categories;\n+\n+\t$from = 0 unless defined $from;\n+\t$to = $#$projlist if (!defined $to || $#$projlist < $to);\n+\n+\tfor my $i ($from .. $to) {\n+\t\tmy $pr = $projlist->[$i];\n+\t\tpush @{$categories{ $pr->{'category'} }}, $pr;\n+\t}\n+\n+\treturn %categories;\n+}\n+\n # print 'sort by' <th> element, generating 'sort by $name' replay link\n # if that order is not selected\n sub print_sort_th {\n@@ -4111,7 +4147,25 @@ sub git_project_list_body {\n \t\t      \"</tr>\\n\";\n \t}\n \n-\tprint_project_rows(\\@projects, $from, $to, $check_forks, $show_ctags);\n+\tif ($projects_list_group_categories) {\n+\t\t# only display categories with projects in the $from-$to window\n+\t\t@projects = sort {$a->{'category'} cmp $b->{'category'}} @projects;\n+\t\tmy %categories = build_projlist_by_category(\\@projects, $from, $to);\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}, undef, undef, $check_forks, $show_ctags);\n+\t\t}\n+\t} else {\n+\t\tprint_project_rows(\\@projects, $from, $to, $check_forks, $show_ctags);\n+\t}\n \n \tif (defined $extra) {\n \t\tprint \"<tr>\\n\";\n-- \n1.5.6.5\n"},{"id":"103724","messageId":"87y6whp56g.wl%seb@cine7.net","threadId":"17649","inReplyTo":null,"subject":"[PATCHv3 2/3 (resend)] gitweb: Split git_project_list_body in two functions","fromName":"Sebastien Cevey","fromEmail":"seb@cine7.net","sentAt":"2008-12-03T23:45:04Z","receivedAt":"2008-12-03T23:45:04Z","isPatch":false,"sender":{"key":"seb@cine7.net","avatar":"https://avatars.githubusercontent.com/u/36964?v=4"},"body":"Extract the printing of project rows on the project page into a\nseparate print_project_rows function. This makes it easier to reuse\nthe code to print different subsets of the whole project list.\n\nThe row printing code is merely moved into a separate function, but\nnote that $projects is passed as a reference now.\n\nSigned-off-by: Sebastien Cevey <seb@cine7.net>\n---\n gitweb/gitweb.perl |  103 +++++++++++++++++++++++++++++-----------------------\n 1 files changed, 57 insertions(+), 46 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex e2550d5..380c702 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -4006,59 +4006,19 @@ sub print_sort_th {\n \t}\n }\n \n-sub git_project_list_body {\n+# print a row for each project in the given list, using the given\n+# range and extra display options\n+sub print_project_rows {\n \t# actually uses global variable $project\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+\tmy ($projects, $from, $to, $check_forks, $show_ctags) = @_;\n \n-\t$order ||= $default_projects_order;\n \t$from = 0 unless defined $from;\n-\t$to = $#projects if (!defined $to || $#projects < $to);\n-\n-\tmy %order_info = (\n-\t\tproject => { key => 'path', type => 'str' },\n-\t\tdescr => { key => 'descr_long', type => 'str' },\n-\t\towner => { key => 'owner', type => 'str' },\n-\t\tage => { key => 'age', type => 'num' }\n-\t);\n-\tmy $oi = $order_info{$order};\n-\tif ($oi->{'type'} eq 'str') {\n-\t\t@projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;\n-\t} else {\n-\t\t@projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;\n-\t}\n+\t$to = $#$projects if (!defined $to || $#$projects < $to);\n \n-\tmy $show_ctags = gitweb_check_feature('ctags');\n-\tif ($show_ctags) {\n-\t\tmy %ctags;\n-\t\tforeach my $p (@projects) {\n-\t\t\tforeach my $ct (keys %{$p->{'ctags'}}) {\n-\t\t\t\t$ctags{$ct} += $p->{'ctags'}->{$ct};\n-\t\t\t}\n-\t\t}\n-\t\tmy $cloud = git_populate_project_tagcloud(\\%ctags);\n-\t\tprint git_show_project_tagcloud($cloud, 64);\n-\t}\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('project', $order, 'Project');\n-\t\tprint_sort_th('descr', $order, 'Description');\n-\t\tprint_sort_th('owner', $order, 'Owner');\n-\t\tprint_sort_th('age', $order, 'Last Change');\n-\t\tprint \"<th></th>\\n\" . # for links\n-\t\t      \"</tr>\\n\";\n-\t}\n \tmy $alternate = 1;\n \tmy $tagfilter = $cgi->param('by_tag');\n \tfor (my $i = $from; $i <= $to; $i++) {\n-\t\tmy $pr = $projects[$i];\n+\t\tmy $pr = $projects->[$i];\n \n \t\tnext if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};\n \t\tnext if $searchtext and not $pr->{'path'} =~ /$searchtext/\n@@ -4102,6 +4062,57 @@ 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 @projects = fill_project_list_info($projlist, $check_forks);\n+\n+\t$order ||= $default_projects_order;\n+\n+\tmy %order_info = (\n+\t\tproject => { key => 'path', type => 'str' },\n+\t\tdescr => { key => 'descr_long', type => 'str' },\n+\t\towner => { key => 'owner', type => 'str' },\n+\t\tage => { key => 'age', type => 'num' }\n+\t);\n+\tmy $oi = $order_info{$order};\n+\tif ($oi->{'type'} eq 'str') {\n+\t\t@projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;\n+\t} else {\n+\t\t@projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;\n+\t}\n+\n+\tmy $show_ctags = gitweb_check_feature('ctags');\n+\tif ($show_ctags) {\n+\t\tmy %ctags;\n+\t\tforeach my $p (@projects) {\n+\t\t\tforeach my $ct (keys %{$p->{'ctags'}}) {\n+\t\t\t\t$ctags{$ct} += $p->{'ctags'}->{$ct};\n+\t\t\t}\n+\t\t}\n+\t\tmy $cloud = git_populate_project_tagcloud(\\%ctags);\n+\t\tprint git_show_project_tagcloud($cloud, 64);\n+\t}\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('project', $order, 'Project');\n+\t\tprint_sort_th('descr', $order, 'Description');\n+\t\tprint_sort_th('owner', $order, 'Owner');\n+\t\tprint_sort_th('age', $order, 'Last Change');\n+\t\tprint \"<th></th>\\n\" . # for links\n+\t\t      \"</tr>\\n\";\n+\t}\n+\n+\tprint_project_rows(\\@projects, $from, $to, $check_forks, $show_ctags);\n+\n \tif (defined $extra) {\n \t\tprint \"<tr>\\n\";\n \t\tif ($check_forks) {\n-- \n1.5.6.5\n"}]}