Skip to content

Commit a75bab5

Browse files
committed
Merge branch 'maint'
* maint: gitweb: Fix project-specific feature override behavior gitweb multiple project roots documentation
2 parents 52ebb06 + 9be3614 commit a75bab5

3 files changed

Lines changed: 85 additions & 9 deletions

File tree

gitweb/README

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,16 @@ If you want to have one URL for both gitweb and your http://
312312
repositories, you can configure apache like this:
313313

314314
<VirtualHost *:80>
315-
ServerName git.example.org
316-
DocumentRoot /pub/git
317-
SetEnv GITWEB_CONFIG /etc/gitweb.conf
315+
ServerName git.example.org
316+
DocumentRoot /pub/git
317+
SetEnv GITWEB_CONFIG /etc/gitweb.conf
318+
319+
# turning on mod rewrite
318320
RewriteEngine on
321+
319322
# make the front page an internal rewrite to the gitweb script
320323
RewriteRule ^/$ /cgi-bin/gitweb.cgi
324+
321325
# make access for "dumb clients" work
322326
RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI} [L,PT]
323327
</VirtualHost>
@@ -343,6 +347,63 @@ something like the following in your gitweb.conf (or gitweb_config.perl) file:
343347
$home_link = "/";
344348

345349

350+
Webserver configuration with multiple projects' root
351+
----------------------------------------------------
352+
353+
If you want to use gitweb with several project roots you can edit your apache
354+
virtual host and gitweb.conf configuration files like this :
355+
356+
virtual host configuration :
357+
358+
<VirtualHost *:80>
359+
ServerName git.example.org
360+
DocumentRoot /pub/git
361+
SetEnv GITWEB_CONFIG /etc/gitweb.conf
362+
363+
# turning on mod rewrite
364+
RewriteEngine on
365+
366+
# make the front page an internal rewrite to the gitweb script
367+
RewriteRule ^/$ /cgi-bin/gitweb.cgi [QSA,L,PT]
368+
369+
# look for a public_git folder in unix users' home
370+
# http://git.example.org/~<user>/
371+
RewriteRule ^/\~([^\/]+)(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]
372+
373+
# http://git.example.org/+<user>/
374+
#RewriteRule ^/\+([^\/]+)(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]
375+
376+
# http://git.example.org/user/<user>/
377+
#RewriteRule ^/user/([^\/]+)/(gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]
378+
379+
# defined list of project roots
380+
RewriteRule ^/scm(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/pub/scm/,L,PT]
381+
RewriteRule ^/var(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/var/git/,L,PT]
382+
383+
# make access for "dumb clients" work
384+
RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI} [L,PT]
385+
</VirtualHost>
386+
387+
gitweb.conf configuration :
388+
389+
$projectroot = $ENV{'GITWEB_PROJECTROOT'} || "/pub/git";
390+
391+
These configurations enable two things. First, each unix user (<user>) of the
392+
server will be able to browse through gitweb git repositories found in
393+
~/public_git/ with the following url : http://git.example.org/~<user>/
394+
395+
If you do not want this feature on your server just remove the second rewrite rule.
396+
397+
If you already use mod_userdir in your virtual host or you don't want to use
398+
the '~' as first character just comment or remove the second rewrite rule and
399+
uncomment one of the following according to what you want.
400+
401+
Second, repositories found in /pub/scm/ and /var/git/ will be accesible
402+
through http://git.example.org/scm/ and http://git.example.org/var/.
403+
You can add as many project roots as you want by adding rewrite rules like the
404+
third and the fourth.
405+
406+
346407
PATH_INFO usage
347408
-----------------------
348409
If you enable PATH_INFO usage in gitweb by putting

gitweb/gitweb.perl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,11 @@ sub gitweb_get_feature {
454454
$feature{$name}{'sub'},
455455
$feature{$name}{'override'},
456456
@{$feature{$name}{'default'}});
457-
if (!$override) { return @defaults; }
457+
# project specific override is possible only if we have project
458+
our $git_dir; # global variable, declared later
459+
if (!$override || !defined $git_dir) {
460+
return @defaults;
461+
}
458462
if (!defined $sub) {
459463
warn "feature $name is not overridable";
460464
return @defaults;
@@ -2212,6 +2216,9 @@ sub config_to_multi {
22122216
sub git_get_project_config {
22132217
my ($key, $type) = @_;
22142218

2219+
# do we have project
2220+
return unless (defined $project && defined $git_dir);
2221+
22152222
# key sanity check
22162223
return unless ($key);
22172224
$key =~ s/^gitweb\.//;

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,21 @@ test_debug 'cat gitweb.log'
591591
# ----------------------------------------------------------------------
592592
# gitweb config and repo config
593593

594-
cat >>gitweb_config.perl <<EOF
595-
596-
\$feature{'blame'}{'override'} = 1;
597-
\$feature{'snapshot'}{'override'} = 1;
598-
\$feature{'avatar'}{'override'} = 1;
594+
cat >>gitweb_config.perl <<\EOF
595+
596+
# turn on override for each overridable feature
597+
foreach my $key (keys %feature) {
598+
if ($feature{$key}{'sub'}) {
599+
$feature{$key}{'override'} = 1;
600+
}
601+
}
599602
EOF
600603

604+
test_expect_success \
605+
'config override: projects list (implicit)' \
606+
'gitweb_run'
607+
test_debug 'cat gitweb.log'
608+
601609
test_expect_success \
602610
'config override: tree view, features not overridden in repo config' \
603611
'gitweb_run "p=.git;a=tree"'

0 commit comments

Comments
 (0)