gitweb: Modularized git_get_project_description to be more generic
PATCH v4 1/3 gitweb: Modularized git_get_project_description to be more generic
Introduce a git_get_file_or_project_config utility function to retrieve a repository variable either from a plain text file in the $GIT_DIR or else from 'gitweb.$variable' in the repository config (e.g. 'description').
---
Sorry, screwed up the previous email trying to keep that From line in the header..
This patch (1/3) is still identical to previous version (v3).
gitweb/gitweb.perl | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-)
gitweb/gitweb.perl +16 -8
@@ -2020,18 +2020,26 @@ sub git_get_path_by_hash { ## ...................................................................... ## git utility functions, directly accessing git repository -sub git_get_project_description { - my $path = shift; +# get the value of a config variable either from a file with the same +# name in the repository, or the gitweb.$name value in the repository +# config file. +sub git_get_file_or_project_config { + 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_file_or_project_config('description', $path); } sub git_get_project_ctags {
Signature · 1 line
1.5.6.5
PATCH v4 2/3 gitweb: Split git_project_list_body in two functions
Extract the printing of project rows on the project page into a separate print_project_rows function. This makes it easier to reuse the code to print different subsets of the whole project list.
The row printing code is merely moved into a separate function, but note that $projects is passed as a reference now.
---
Fixed the patch to apply cleanly on the current HEAD.
gitweb/gitweb.perl | 103 +++++++++++++++++++++++++++++----------------------- 1 files changed, 57 insertions(+), 46 deletions(-)
gitweb/gitweb.perl +57 -46
@@ -3996,59 +3996,19 @@ sub print_sort_th { } } -sub git_project_list_body { +# print a row for each project in the given list, using the given +# range and extra display options +sub print_project_rows { # actually uses global variable $project - my ($projlist, $order, $from, $to, $extra, $no_header) = @_; - - my $check_forks = gitweb_check_feature('forks'); - my @projects = fill_project_list_info($projlist, $check_forks); + my ($projects, $from, $to, $check_forks, $show_ctags) = @_; - $order ||= $default_projects_order; $from = 0 unless defined $from; - $to = $#projects if (!defined $to || $#projects < $to); - - my %order_info = ( - project => { key => 'path', type => 'str' }, - descr => { key => 'descr_long', type => 'str' }, - owner => { key => 'owner', type => 'str' }, - age => { key => 'age', type => 'num' } - ); - my $oi = $order_info{$order}; - if ($oi->{'type'} eq 'str') { - @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects; - } else { - @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects; - } + $to = $#$projects if (!defined $to || $#$projects < $to); - my $show_ctags = gitweb_check_feature('ctags'); - if ($show_ctags) { - my %ctags; - foreach my $p (@projects) { - foreach my $ct (keys %{$p->{'ctags'}}) { - $ctags{$ct} += $p->{'ctags'}->{$ct}; - } - } - my $cloud = git_populate_project_tagcloud(\%ctags); - print git_show_project_tagcloud($cloud, 64); - } - - print "<table class=\"project_list\">\n"; - unless ($no_header) { - print "<tr>\n"; - if ($check_forks) { - print "<th></th>\n"; - } - print_sort_th('project', $order, 'Project'); - print_sort_th('descr', $order, 'Description'); - print_sort_th('owner', $order, 'Owner'); - print_sort_th('age', $order, 'Last Change'); - print "<th></th>\n" . # for links - "</tr>\n"; - } my $alternate = 1; my $tagfilter = $cgi->param('by_tag'); for (my $i = $from; $i <= $to; $i++) { - my $pr = $projects[$i]; + my $pr = $projects->[$i]; next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}}; next if $searchtext and not $pr->{'path'} =~ /$searchtext/
@@ -4092,6 +4052,57 @@ sub git_project_list_body { "</td>\n" . "</tr>\n"; } +} + +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); + + $order ||= $default_projects_order; + + my %order_info = ( + project => { key => 'path', type => 'str' }, + descr => { key => 'descr_long', type => 'str' }, + owner => { key => 'owner', type => 'str' }, + age => { key => 'age', type => 'num' } + ); + my $oi = $order_info{$order}; + if ($oi->{'type'} eq 'str') { + @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects; + } else { + @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects; + } + + my $show_ctags = gitweb_check_feature('ctags'); + if ($show_ctags) { + my %ctags; + foreach my $p (@projects) { + foreach my $ct (keys %{$p->{'ctags'}}) { + $ctags{$ct} += $p->{'ctags'}->{$ct}; + } + } + my $cloud = git_populate_project_tagcloud(\%ctags); + print git_show_project_tagcloud($cloud, 64); + } + + print "<table class=\"project_list\">\n"; + unless ($no_header) { + print "<tr>\n"; + if ($check_forks) { + print "<th></th>\n"; + } + print_sort_th('project', $order, 'Project'); + print_sort_th('descr', $order, 'Description'); + print_sort_th('owner', $order, 'Owner'); + print_sort_th('age', $order, 'Last Change'); + print "<th></th>\n" . # for links + "</tr>\n"; + } + + print_project_rows(\@projects, $from, $to, $check_forks, $show_ctags); + if (defined $extra) { print "<tr>\n"; if ($check_forks) {
Signature · 1 line
1.5.6.5
PATCH v4 3/3 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 '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.
---
Simplified the patch according to Jakub's suggestion to filter $from/$to for categories in build_projlist_by_category (requires @projects to be sorted by category behorehand).
gitweb/README | 16 +++++++++++++ gitweb/gitweb.css | 7 ++++++ gitweb/gitweb.perl | 60 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 80 insertions(+), 3 deletions(-)
gitweb/README +16 -0
@@ -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
gitweb/gitweb.css +7 -0
@@ -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; }
gitweb/gitweb.perl +57 -3
96 lines not on this page · raw message
Signature · 1 line
1.5.6.5