patches: update gitweb patch set
[git-osx-installer.git] / patches / gitweb / q / gitweb-support-for-no-project-list-on-gitweb-front-p.diff
blob117c0b1d5178ee9450e9b7e45d719775b11e9416
1 Subject: [PATCH] gitweb: support for no project list on gitweb front page
3 On very large sites like repo.or.cz (but maybe also git.debian.org,
4 git.kernel.org, etc.), it is desirable not to have the project list
5 on the front page since generating it is significant overhead and it
6 takes significant data transfer and load time for the user, who might
7 prefer to instead use the search form and possibly content tags to
8 navigate to the target project. A link to the full list of projects is
9 still available on the front page for users who wish to browse it. The
10 whole feature is turned off by default.
12 The patch introduces a new config variable $frontpage_no_project_list,
13 by default 0 keeping the current behavior; if set to 1, no project list
14 will be shown, but all projects will be still scanned if ctags are
15 enabled; if set to 2, no project will be shown and no projects will
16 be scanned while showing the front page. The compromise value of 1 is
17 useful for sites where project scan time is not an issue or which
18 use additional project list caching patches.
20 The patch furthermore modifies project_list action not to show the
21 index text, and introduces new default action frontpage which is by
22 default identical to old project_list action, but can be further
23 controlled by the $frontpage_no_project_list variable.
25 Signed-off-by: Petr Baudis <pasky@ucw.cz>
26 Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
27 ---
28 Documentation/gitweb.conf.txt | 9 ++++++
29 Documentation/gitweb.txt | 8 +++--
30 gitweb/gitweb.perl | 68 +++++++++++++++++++++++++++++++++++++------
31 gitweb/static/gitweb.css | 5 ++++
32 4 files changed, 79 insertions(+), 11 deletions(-)
34 diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
35 index 7c7c7eb9..841e7dad 100644
36 --- a/Documentation/gitweb.conf.txt
37 +++ b/Documentation/gitweb.conf.txt
38 @@ -424,6 +424,15 @@ $default_projects_order::
40 Default value is "project". Unknown value means unsorted.
42 +$frontpage_no_project_list::
43 + If 0, the gitweb frontpage will contain the project list; if 1 instead,
44 + it will contain just the index text, search form, tag cloud (if enabled)
45 + and a link to the actual project list. The page is reduced, but all
46 + projects still need to be scanned for the tag cloud construction. If the
47 + option is set to 2, not even the tag cloud will be shown; this is fastest.
48 + This option is useful for sites with large amount of projects. The default
49 + is 0.
52 Changing gitweb's behavior
53 ~~~~~~~~~~~~~~~~~~~~~~~~~~
54 diff --git a/Documentation/gitweb.txt b/Documentation/gitweb.txt
55 index cd9c8951..e87a461b 100644
56 --- a/Documentation/gitweb.txt
57 +++ b/Documentation/gitweb.txt
58 @@ -324,9 +324,13 @@ Actions:
59 ~~~~~~~~
60 The standard actions are:
62 +frontpage::
63 + Same as project_list unless `$frontpage_no_project_list` is set to a
64 + non-zero value. This is the default command if no repository is
65 + specified in the URL.
67 project_list::
68 - Lists the available Git repositories. This is the default command if no
69 - repository is specified in the URL.
70 + Lists the available Git repositories.
72 summary::
73 Displays summary about given repository. This is the default command if
74 diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
75 index 5aa78166..76815232 100755
76 --- a/gitweb/gitweb.perl
77 +++ b/gitweb/gitweb.perl
78 @@ -207,6 +207,11 @@ our $prevent_xss = 0;
79 # [Default: highlight]
80 our $highlight_bin = "++HIGHLIGHT_BIN++";
82 +# Whether to include project list on the gitweb front page; 0 means yes,
83 +# 1 means no list but show tag cloud if enabled (all projects still need
84 +# to be scanned), 2 means no list and no tag cloud (very fast)
85 +our $frontpage_no_project_list = 0;
87 # information about snapshot formats that gitweb is capable of serving
88 our %known_snapshot_formats = (
89 # name => {
90 @@ -888,6 +893,7 @@ our %actions = (
91 "object" => \&git_object,
92 # those below don't need $project
93 "opml" => \&git_opml,
94 + "frontpage" => \&git_frontpage,
95 "project_list" => \&git_project_list,
96 "project_index" => \&git_project_index,
98 @@ -1249,13 +1255,13 @@ sub dispatch {
99 } elsif (defined $project) {
100 $action = 'summary';
101 } else {
102 - $action = 'project_list';
103 + $action = 'frontpage';
106 if (!defined($actions{$action})) {
107 die_error(400, "Unknown action");
109 - if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
110 + if ($action !~ m/^(?:opml|frontpage|project_list|project_index)$/ &&
111 !$project) {
112 die_error(400, "Project needed");
114 @@ -5632,7 +5638,7 @@ sub git_project_search_form {
116 my $limit = '';
117 if ($project_filter) {
118 - $limit = " in '$project_filter/'";
119 + $limit = " in '$project_filter'";
122 print "<div class=\"projsearch\">\n";
123 @@ -5649,9 +5655,16 @@ sub git_project_search_form {
124 "</span>\n" .
125 $cgi->submit(-name => 'btnS', -value => 'Search') .
126 $cgi->end_form() . "\n" .
127 + "<span class=\"projectlist_link\">" .
128 $cgi->a({-href => href(project => undef, searchtext => undef,
129 + action => 'project_list',
130 project_filter => $project_filter)},
131 - esc_html("List all projects$limit")) . "<br />\n";
132 + esc_html("List all projects$limit")) . "</span><br />\n";
133 + print "<span class=\"projectlist_link\">" .
134 + $cgi->a({-href => href(project => undef, searchtext => undef,
135 + action => 'project_list',
136 + project_filter => undef)},
137 + esc_html("List all projects")) . "</span>\n" if $project_filter;
138 print "</div>\n";
141 @@ -5890,7 +5903,7 @@ sub git_project_list_body {
142 if ($from > $to) {
143 print "<center>\n".
144 "<b>No such projects found</b><br />\n".
145 - "Click ".$cgi->a({-href=>href(project=>undef)},"here")." to view all projects<br />\n".
146 + "Click ".$cgi->a({-href=>href(project=>undef,action=>'project_list')},"here")." to view all projects<br />\n".
147 "</center>\n<br />\n";
148 return;
150 @@ -6572,7 +6585,8 @@ sub git_search_grep_body {
151 ## ======================================================================
152 ## actions
154 -sub git_project_list {
155 +sub git_project_list_load {
156 + my $empty_list_ok = shift;
157 my $order = $input_params{'order'};
158 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
159 die_error(400, "Unknown order parameter");
160 @@ -6580,18 +6594,54 @@ sub git_project_list {
162 my @list = git_get_projects_list($project_filter, $strict_export);
163 if (!@list) {
164 - die_error(404, "No projects found");
165 + die_error(404, "No projects found") unless $empty_list_ok;
168 + return (\@list, $order);
171 +sub git_frontpage {
172 + my ($projlist, $order);
174 + if ($frontpage_no_project_list) {
175 + $project = undef;
176 + $project_filter = undef;
177 + } else {
178 + ($projlist, $order) = git_project_list_load(1);
180 git_header_html();
181 if (defined $home_text && -f $home_text) {
182 print "<div class=\"index_include\">\n";
183 insert_file($home_text);
184 print "</div>\n";
187 git_project_search_form($searchtext, $search_use_regexp);
188 - git_project_list_body(\@list, $order);
189 + if ($frontpage_no_project_list) {
190 + my $show_ctags = gitweb_check_feature('ctags');
191 + if ($frontpage_no_project_list == 1 and $show_ctags) {
192 + my @projects = git_get_projects_list($project_filter, $strict_export);
193 + @projects = filter_forks_from_projects_list(\@projects) if gitweb_check_feature('forks');
194 + @projects = fill_project_list_info(\@projects, 'ctags');
195 + my $ctags = git_gather_all_ctags(\@projects);
196 + my $cloud = git_populate_project_tagcloud($ctags, 'project_list');
197 + print git_show_project_tagcloud($cloud, 64);
199 + } else {
200 + git_project_list_body($projlist, $order);
202 + git_footer_html();
205 +sub git_project_list {
206 + my ($projlist, $order) = git_project_list_load();
207 + git_header_html();
208 + if (!$frontpage_no_project_list && defined $home_text && -f $home_text) {
209 + print "<div class=\"index_include\">\n";
210 + insert_file($home_text);
211 + print "</div>\n";
213 + git_project_search_form();
214 + git_project_list_body($projlist, $order);
215 git_footer_html();
218 diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css
219 index 420c99fa..1710b06f 100644
220 --- a/gitweb/static/gitweb.css
221 +++ b/gitweb/static/gitweb.css
222 @@ -635,6 +635,11 @@ span.match {
223 color: #e00000;
226 +span.projectlist_link {
227 + text-align: center;
228 + font-weight: bold;
231 div.binary {
232 font-style: italic;