From 6f39397c8f2b6be17a050e9c2cf562425fcfb036 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Wed, 4 Nov 2009 01:04:23 +0100 Subject: [PATCH] gitweb: support for no project list on gitweb front page On very large sites like repo.or.cz (but maybe also git.debian.org, git.kernel.org, etc.), it is desirable not to have the project list on the front page since generating it is significant overhead and it takes significant data transfer and load time for the user, who might prefer to instead use the search form and possibly content tags to navigate to the target project. A link to the full list of projects is still available on the front page for users who wish to browse it. The whole feature is turned off by default. The patch introduces a new config variable $frontpage_no_project_list, by default 0 keeping the current behavior; if set to 1, no project list will be shown, but all projects will be still scanned if ctags are enabled; if set to 2, no project will be shown and no projects will be scanned while showing the front page. The compromise value of 1 is useful for sites where project scan time is not an issue or which use additional project list caching patches. The patch furthermore modifies project_list action not to show the index text, and introduces new default action frontpage which is by default identical to old project_list action, but can be further controlled by the $frontpage_no_project_list variable. Signed-off-by: Petr Baudis Signed-off-by: Kyle J. McKay --- Documentation/gitweb.conf.txt | 9 +++++++++ gitweb/gitweb.perl | 45 ++++++++++++++++++++++++++++++++++++++----- gitweb/static/gitweb.css | 5 +++++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt index ebe7a6c24c..82484eeb17 100644 --- a/Documentation/gitweb.conf.txt +++ b/Documentation/gitweb.conf.txt @@ -424,6 +424,15 @@ $default_projects_order:: + Default value is "project". Unknown value means unsorted. +$frontpage_no_project_list:: + If 0, the gitweb frontpage will contain the project list; if 1 instead, + it will contain just the index text, search form, tag cloud (if enabled) + and a link to the actual project list. The page is reduced, but all + projects still need to be scanned for the tag cloud construction. If the + option is set to 2, not even the tag cloud will be shown; this is fastest. + This option is useful for sites with large amount of projects. The default + is 0. + Changing gitweb's behavior ~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index f9a6c5ff59..58534f8844 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -198,6 +198,11 @@ our $prevent_xss = 0; # [Default: highlight] our $highlight_bin = "++HIGHLIGHT_BIN++"; +# Whether to include project list on the gitweb front page; 0 means yes, +# 1 means no list but show tag cloud if enabled (all projects still need +# to be scanned), 2 means no list and no tag cloud (very fast) +our $frontpage_no_project_list = 0; + # information about snapshot formats that gitweb is capable of serving our %known_snapshot_formats = ( # name => { @@ -860,6 +865,7 @@ our %actions = ( "object" => \&git_object, # those below don't need $project "opml" => \&git_opml, + "frontpage" => \&git_frontpage, "project_list" => \&git_project_list, "project_index" => \&git_project_index, ); @@ -1227,7 +1233,7 @@ sub dispatch { if (!defined($actions{$action})) { die_error(400, "Unknown action"); } - if ($action !~ m/^(?:opml|project_list|project_index)$/ && + if ($action !~ m/^(?:opml|frontpage|project_list|project_index)$/ && !$project) { die_error(400, "Project needed"); } @@ -6450,7 +6456,8 @@ sub git_search_grep_body { ## ====================================================================== ## actions -sub git_project_list { +sub git_project_list_load { + my $empty_list_ok = shift; my $order = $input_params{'order'}; if (defined $order && $order !~ m/none|project|descr|owner|age/) { die_error(400, "Unknown order parameter"); @@ -6458,18 +6465,46 @@ sub git_project_list { my @list = git_get_projects_list($project_filter, $strict_export); if (!@list) { - die_error(404, "No projects found"); + die_error(404, "No projects found") unless $empty_list_ok; } + return (\@list, $order); +} + +sub git_frontpage { + my ($projlist, $order); + ($projlist, $order) = git_project_list_load(1) if not $frontpage_no_project_list; git_header_html(); if (defined $home_text && -f $home_text) { print "
\n"; insert_file($home_text); print "
\n"; } - git_project_search_form($searchtext, $search_use_regexp); - git_project_list_body(\@list, $order); + if (not $frontpage_no_project_list) { + git_project_list_body($projlist, $order); + } else { + my $show_ctags = gitweb_check_feature('ctags'); + if ($frontpage_no_project_list == 1 and $show_ctags) { + my @projects = git_get_projects_list($project_filter, $strict_export); + @projects = filter_forks_from_projects_list(\@projects) if gitweb_check_feature('forks'); + @projects = fill_project_list_info(\@projects, 'ctags'); + my $ctags = git_gather_all_ctags(\@projects); + my $cloud = git_populate_project_tagcloud($ctags, 'project_list'); + print git_show_project_tagcloud($cloud, 64); + } + print "

" . + $cgi->a({-href => href(action=>'project_list')}, "Browse all projects") . + "

\n"; + } + git_footer_html(); +} + +sub git_project_list { + my ($projlist, $order) = git_project_list_load(); + git_header_html(); + git_project_search_form(); + git_project_list_body($projlist, $order); git_footer_html(); } diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css index 3212601032..25b490650b 100644 --- a/gitweb/static/gitweb.css +++ b/gitweb/static/gitweb.css @@ -110,6 +110,11 @@ div.readme { padding: 8px; } +p.projectlist_link { + text-align: center; + font-weight: bold; +} + a.title:hover { background-color: #d9d8d1; } -- 2.11.4.GIT