Skip to content

Commit d940c90

Browse files
theefergitster
authored andcommitted
gitweb: Optional grouping of projects by category
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 'gitweb.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 code. The CSS for categories is inspired from Gustavo Sverzut Barbieri's patch to group projects by path. Thanks to Florian Ragwitz for Perl tips. [jn: Updated to post restructuring projects list generation, fixed bugs, added very basic test in t9500 that there are no warnings from Perl.] Signed-off-by: Sebastien Cevey <[email protected]> Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4e3b32 commit d940c90

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

gitweb/README

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ not include variables usually directly set during build):
207207
full description is available as 'title' attribute (usually shown on
208208
mouseover). By default set to 25, which might be too small if you
209209
use long project descriptions.
210+
* $projects_list_group_categories
211+
Enables the grouping of projects by category on the project list page.
212+
The category of a project is determined by the $GIT_DIR/category
213+
file or the 'gitweb.category' variable in its repository configuration.
214+
Disabled by default.
215+
* $project_list_default_category
216+
Default category for projects for which none is specified. If set
217+
to the empty string, such projects will remain uncategorized and
218+
listed at the top, above categorized projects.
210219
* @git_base_url_list
211220
List of git base URLs used for URL to where fetch project from, shown
212221
in project summary page. Full URL is "$git_base_url/$project".
@@ -314,6 +323,13 @@ You can use the following files in repository:
314323
from the template during repository creation. You can use the
315324
gitweb.description repo configuration variable, but the file takes
316325
precedence.
326+
* category (or gitweb.category)
327+
Singe line category of a project, used to group projects if
328+
$projects_list_group_categories is enabled. By default (file and
329+
configuration variable absent), uncategorized projects are put in
330+
the $project_list_default_category category. You can use the
331+
gitweb.category repo configuration variable, but the file takes
332+
precedence.
317333
* cloneurl (or multiple-valued gitweb.url)
318334
File with repository URL (used for clone and fetch), one per line.
319335
Displayed in the project summary page. You can use multiple-valued

gitweb/gitweb.perl

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ sub evaluate_uri {
115115
# the width (in characters) of the projects list "Description" column
116116
our $projects_list_description_width = 25;
117117

118+
# group projects by category on the projects list
119+
# (enabled if this variable evaluates to true)
120+
our $projects_list_group_categories = 0;
121+
122+
# default category if none specified
123+
# (leave the empty string for no category)
124+
our $project_list_default_category = "";
125+
118126
# default order of projects list
119127
# valid values are none, project, descr, owner, and age
120128
our $default_projects_order = "project";
@@ -2584,6 +2592,12 @@ sub git_get_project_description {
25842592
return git_get_file_or_project_config($path, 'description');
25852593
}
25862594

2595+
sub git_get_project_category {
2596+
my $path = shift;
2597+
return git_get_file_or_project_config($path, 'category');
2598+
}
2599+
2600+
25872601
# supported formats:
25882602
# * $GIT_DIR/ctags/<tagname> file (in 'ctags' subdirectory)
25892603
# - if its contents is a number, use it as tag weight,
@@ -4877,8 +4891,9 @@ sub git_patchset_body {
48774891

48784892
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
48794893

4880-
# fills project list info (age, description, owner, forks) for each
4881-
# project in the list, removing invalid projects from returned list
4894+
# fills project list info (age, description, owner, category, forks)
4895+
# for each project in the list, removing invalid projects from
4896+
# returned list
48824897
# NOTE: modifies $projlist, but does not remove entries from it
48834898
sub fill_project_list_info {
48844899
my $projlist = shift;
@@ -4904,6 +4919,12 @@ sub fill_project_list_info {
49044919
if ($show_ctags) {
49054920
$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
49064921
}
4922+
if ($projects_list_group_categories && !defined $pr->{'category'}) {
4923+
my $cat = git_get_project_category($pr->{'path'}) ||
4924+
$project_list_default_category;
4925+
$pr->{'category'} = to_utf8($cat);
4926+
}
4927+
49074928
push @projects, $pr;
49084929
}
49094930

@@ -4931,6 +4952,23 @@ sub sort_projects_list {
49314952
return @projects;
49324953
}
49334954

4955+
# returns a hash of categories, containing the list of project
4956+
# belonging to each category
4957+
sub build_projlist_by_category {
4958+
my ($projlist, $from, $to) = @_;
4959+
my %categories;
4960+
4961+
$from = 0 unless defined $from;
4962+
$to = $#$projlist if (!defined $to || $#$projlist < $to);
4963+
4964+
for (my $i = $from; $i <= $to; $i++) {
4965+
my $pr = $projlist->[$i];
4966+
push @{$categories{ $pr->{'category'} }}, $pr;
4967+
}
4968+
4969+
return wantarray ? %categories : \%categories;
4970+
}
4971+
49344972
# print 'sort by' <th> element, generating 'sort by $name' replay link
49354973
# if that order is not selected
49364974
sub print_sort_th {
@@ -5059,7 +5097,25 @@ sub git_project_list_body {
50595097
"</tr>\n";
50605098
}
50615099

5062-
git_project_list_rows(\@projects, $from, $to, $check_forks);
5100+
if ($projects_list_group_categories) {
5101+
# only display categories with projects in the $from-$to window
5102+
@projects = sort {$a->{'category'} cmp $b->{'category'}} @projects[$from..$to];
5103+
my %categories = build_projlist_by_category(\@projects, $from, $to);
5104+
foreach my $cat (sort keys %categories) {
5105+
unless ($cat eq "") {
5106+
print "<tr>\n";
5107+
if ($check_forks) {
5108+
print "<td></td>\n";
5109+
}
5110+
print "<td class=\"category\" colspan=\"5\">".esc_html($cat)."</td>\n";
5111+
print "</tr>\n";
5112+
}
5113+
5114+
git_project_list_rows($categories{$cat}, undef, undef, $check_forks);
5115+
}
5116+
} else {
5117+
git_project_list_rows(\@projects, $from, $to, $check_forks);
5118+
}
50635119

50645120
if (defined $extra) {
50655121
print "<tr>\n";

gitweb/static/gitweb.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ td.current_head {
295295
text-decoration: underline;
296296
}
297297

298+
td.category {
299+
background-color: #d9d8d1;
300+
border-top: 1px solid #000000;
301+
border-left: 1px solid #000000;
302+
font-weight: bold;
303+
}
304+
298305
table.diff_tree span.file_status.new {
299306
color: #008000;
300307
}

t/t9500-gitweb-standalone-no-errors.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,12 @@ test_expect_success \
644644
'ctags: search projects by non existent tag' \
645645
'gitweb_run "by_tag=non-existent"'
646646

647+
# ----------------------------------------------------------------------
648+
# categories
649+
650+
test_expect_success \
651+
'categories: projects list, only default category' \
652+
'echo "\$projects_list_group_categories = 1;" >>gitweb_config.perl &&
653+
gitweb_run'
654+
647655
test_done

0 commit comments

Comments
 (0)