Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
* maint:
  gitweb: Fix project-specific feature override behavior
  gitweb multiple project roots documentation
  • Loading branch information
Junio C Hamano committed Mar 2, 2010
2 parents 52ebb06 + 9be3614 commit a75bab5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 9 deletions.
67 changes: 64 additions & 3 deletions gitweb/README
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,16 @@ If you want to have one URL for both gitweb and your http://
repositories, you can configure apache like this:

<VirtualHost *:80>
ServerName git.example.org
DocumentRoot /pub/git
SetEnv GITWEB_CONFIG /etc/gitweb.conf
ServerName git.example.org
DocumentRoot /pub/git
SetEnv GITWEB_CONFIG /etc/gitweb.conf

# turning on mod rewrite
RewriteEngine on

# make the front page an internal rewrite to the gitweb script
RewriteRule ^/$ /cgi-bin/gitweb.cgi

# make access for "dumb clients" work
RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI} [L,PT]
</VirtualHost>
Expand All @@ -343,6 +347,63 @@ something like the following in your gitweb.conf (or gitweb_config.perl) file:
$home_link = "/";


Webserver configuration with multiple projects' root
----------------------------------------------------

If you want to use gitweb with several project roots you can edit your apache
virtual host and gitweb.conf configuration files like this :

virtual host configuration :

<VirtualHost *:80>
ServerName git.example.org
DocumentRoot /pub/git
SetEnv GITWEB_CONFIG /etc/gitweb.conf

# turning on mod rewrite
RewriteEngine on

# make the front page an internal rewrite to the gitweb script
RewriteRule ^/$ /cgi-bin/gitweb.cgi [QSA,L,PT]

# look for a public_git folder in unix users' home
# http://git.example.org/~<user>/
RewriteRule ^/\~([^\/]+)(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]

# http://git.example.org/+<user>/
#RewriteRule ^/\+([^\/]+)(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]

# http://git.example.org/user/<user>/
#RewriteRule ^/user/([^\/]+)/(gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]

# defined list of project roots
RewriteRule ^/scm(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/pub/scm/,L,PT]
RewriteRule ^/var(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/var/git/,L,PT]

# make access for "dumb clients" work
RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI} [L,PT]
</VirtualHost>

gitweb.conf configuration :

$projectroot = $ENV{'GITWEB_PROJECTROOT'} || "/pub/git";

These configurations enable two things. First, each unix user (<user>) of the
server will be able to browse through gitweb git repositories found in
~/public_git/ with the following url : http://git.example.org/~<user>/

If you do not want this feature on your server just remove the second rewrite rule.

If you already use mod_userdir in your virtual host or you don't want to use
the '~' as first character just comment or remove the second rewrite rule and
uncomment one of the following according to what you want.

Second, repositories found in /pub/scm/ and /var/git/ will be accesible
through http://git.example.org/scm/ and http://git.example.org/var/.
You can add as many project roots as you want by adding rewrite rules like the
third and the fourth.


PATH_INFO usage
-----------------------
If you enable PATH_INFO usage in gitweb by putting
Expand Down
9 changes: 8 additions & 1 deletion gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ sub gitweb_get_feature {
$feature{$name}{'sub'},
$feature{$name}{'override'},
@{$feature{$name}{'default'}});
if (!$override) { return @defaults; }
# project specific override is possible only if we have project
our $git_dir; # global variable, declared later
if (!$override || !defined $git_dir) {
return @defaults;
}
if (!defined $sub) {
warn "feature $name is not overridable";
return @defaults;
Expand Down Expand Up @@ -2212,6 +2216,9 @@ sub config_to_multi {
sub git_get_project_config {
my ($key, $type) = @_;

# do we have project
return unless (defined $project && defined $git_dir);

# key sanity check
return unless ($key);
$key =~ s/^gitweb\.//;
Expand Down
18 changes: 13 additions & 5 deletions t/t9500-gitweb-standalone-no-errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,21 @@ test_debug 'cat gitweb.log'
# ----------------------------------------------------------------------
# gitweb config and repo config

cat >>gitweb_config.perl <<EOF
\$feature{'blame'}{'override'} = 1;
\$feature{'snapshot'}{'override'} = 1;
\$feature{'avatar'}{'override'} = 1;
cat >>gitweb_config.perl <<\EOF
# turn on override for each overridable feature
foreach my $key (keys %feature) {
if ($feature{$key}{'sub'}) {
$feature{$key}{'override'} = 1;
}
}
EOF

test_expect_success \
'config override: projects list (implicit)' \
'gitweb_run'
test_debug 'cat gitweb.log'

test_expect_success \
'config override: tree view, features not overridden in repo config' \
'gitweb_run "p=.git;a=tree"'
Expand Down

0 comments on commit a75bab5

Please sign in to comment.