gitweb: make static files accessible with PATH_INFO
PATCH v4 1/2 gitweb: make static files accessible with PATH_INFO
When gitweb is invoked with PATH_INFO and links to static files such as the CSS and favicon/shortcut icon are relative URLs with relative paths (as is the case when using the default Makefile), these files are not accessible beyond the project list and summary page (e.g. in shortlog or commit view).
Fix this by adding a <base> tag pointing to the script's own URL, that ensure that all relative paths will be based on this.
--- gitweb/gitweb.perl | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
gitweb/gitweb.perl +5 -0
@@ -2901,6 +2901,11 @@ sub git_header_html { <meta name="robots" content="index, nofollow"/> <title>$title</title> EOF +# the stylesheet, favicon etc urls won't work correctly with path_info unless we +# set the appropriate base URL + if ($ENV{'PATH_INFO'}) { + print "<base href='".esc_url($my_url)."' />\n"; + } # print out each stylesheet that exist if (defined $stylesheet) { #provides backwards capability for those people who define style sheet in a config file
Signature · 1 line
1.5.6.5
PATCH v4 2/2 gitweb: webserver config for PATH_INFO
Document some possible Apache configurations when the path_info feature is enabled in gitweb.
---
So I decided to document the best way to set up the web server with the path_info feature. I particularly like the second trick, although I haven't found a way to make git-daemon accept both git://git.example.com/project andgit://git.example.com/project.git when the project dirs don't have the .git extensions (e.g. /pub/git/project instead of /pub/git/project.git)
gitweb/README | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 76 insertions(+), 0 deletions(-)
gitweb/README +76 -0
@@ -322,6 +322,82 @@ something like the following in your gitweb.conf (or gitweb_config.perl) file: $home_link = "/"; +PATH_INFO usage +----------------------- +If you enable PATH_INFO usage in gitweb by putting + + $feature{'pathinfo'}{'default'} = [1]; + +in your gitweb.conf, it is possible to set up your server so that it +consumes and produces URLs in the form + +http://git.example.com/project.git/shortlog/sometag + +by using a configuration such as the following, that assumes that +/var/www/gitweb is the DocumentRoot of your webserver, and that it +contains the gitweb.cgi script and complementary static files +(stylesheet, favicon): + +<VirtualHost *:80> + ServerAlias git.example.com + + DocumentRoot /var/www/gitweb + + <Directory /var/www/gitweb> + Options ExecCGI + AddHandler cgi-script cgi + + DirectoryIndex gitweb.cgi + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^.* /gitweb.cgi/$0 [L,PT] + </Directory> +</VirtualHost> + +The rewrite rule guarantees that existing static files will be properly +served, whereas any other URL will be passed to gitweb as PATH_INFO +parameter. + +Notice that in this case you don't need special settings for +@stylesheets, $my_uri and $home_link, but you lose "dumb client" access +to your project .git dirs. A possible workaround for the latter is the +following: in your project root dir (e.g. /pub/git) have the projects +named without a .git extension (e.g. /pub/git/project instead of +/pub/git/project.git) and configure Apache as follows: + +<VirtualHost *:80> + ServerAlias git.example.com + + DocumentRoot /var/www/gitweb + + AliasMatch ^(/.*?)(\.git)(/.*)? /pub/git$1$3 + <Directory /var/www/gitweb> + Options ExecCGI + AddHandler cgi-script cgi + + DirectoryIndex gitweb.cgi + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^.* /gitweb.cgi/$0 [L,PT] + </Directory> +</VirtualHost> + +The additional AliasMatch makes it so that + +http://git.example.com/project.git + +will give raw access to the project's git dir (so that the project can +be cloned), while + +http://git.example.com/project + +will provide human-friendly gitweb access. + + Originally written by: Kay Sievers <[email protected]>
Signature · 1 line
1.5.6.5
Quoted 8 lines · Giuseppe Bilotta
When gitweb is invoked with
PATH_INFOand links to static files such as the CSS and favicon/shortcut icon are relative URLs with relative paths (as is the case when using the defaultMakefile), these files are not accessible beyond the project list and summary page (e.g. in shortlog or commit view).Fix this by adding a <base> tag pointing to the script's own URL, that ensure that all relative paths will be based on this.
I think it is a very good idea, good patch (now with esc_url, just in case, even though I think it should be needed), and commit message has all info that it should have. But I think that it could be phrased
better: instead of one long sentence, perhaps split it into few sentences, each dealing with one issue. Something like below:
-- >8 --
Gitweb links to a few static files: CSS stylesheet, favicon/shortcut icon and git logo. When links to those files are given by relative URLs with relative paths (not starting with '/'), and gitweb is invoked with (non empty) PATH_INFO, these files are not accessible beyond projects list and 'summary' view for a project (e.g. in 'shortlog' or 'commit' view). Default Makefile rules use base filenames for those static files.
Fix this by adding <base> element pointing to script's own URL, which ensures that all relative paths relative URLs will be resolved correctly.
-- 8< --
Gaaahhh... I think this version could be better, but I cannot think how it should look like...
Quoted 11 lines
Signed-off-by Giuseppe Bilotta <[email protected]>--- gitweb/gitweb.perl | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)gitweb/gitweb.perl +0
-0
gitweb/gitweb.perl sub git_header_html { · line 2905
Quoted 5 lines
gitweb/gitweb.perl +2
-0@@ -2901,6 +2901,11 @@ sub git_header_html { <meta name="robots" content="index, nofollow"/> <title>$title</title> EOF +# the stylesheet, favicon etc urls won't work correctly with path_info unless we +# set the appropriate base URL
BTW. I think there should be independent patch making those comments indented properly...
gitweb/gitweb.perl sub git_header_html { · line 2907
Quoted 2 lines
gitweb/gitweb.perl +2
-0+ if ($ENV{'PATH_INFO'}) { + print "<base href='".esc_url($my_url)."' />\n";
Errr... here we use ' as attribute delimiter, while everywhere else we use "; I don't know if esc_url deals correctly with this... it does as neither " nor ' is in "allowed" list, but I'd personally use
+ print '<base href="'.esc_url($my_url).'" />'."\n";
Quoted 8 lines
gitweb/gitweb.perl +1
-0+ } # print out each stylesheet that exist if (defined $stylesheet) { #provides backwards capability for those people who define style sheet in a config fileSignature · 1 line
1.5.6.5
Signature · 2 lines
Jakub Narebski Poland