CGI to transparently translate gitweb to cgit

Konstantin Ryabitsev mricon at kernel.org
Wed Jun 17 20:47:24 CEST 2015


Hello, all:

Peter Anvin wrote a CGI to transition from gitweb to cgit. I was
wondering if it makes sense to incorporate it into cgit as part of contrib?

http://git.zytor.com/users/hpa/cgit/gitweb2cgit.git/tree/gitweb2cgit.cgi

At least hopefully this will come in handy for someone so they don't
have to create terrible monstrosities with rewrite rules (like I did for
kernel.org).

Best,
-K

-------- Forwarded Message --------
Subject: Re: Migrating from gitweb to cgit
Date: Tue, 16 Jun 2015 12:52:09 -0700
From: H. Peter Anvin <hpa at zytor.com>
To: Konstantin Ryabitsev <mricon at kernel.org>

On 06/12/2015 05:26 AM, Konstantin Ryabitsev wrote:
> On 11/06/15 07:16 PM, H. Peter Anvin wrote:
>> Cool.  I ran into a set of transformation rules on the web earlier and
>> hacked up a CGI script (as I just don't trust RewriteEngine to do this
>> stuff sanely.)
>>
>> This is the latest version of it:
>>
>> http://git.zytor.com/users/hpa/cgit/gitweb2cgit.git/tree/gitweb2cgit.cgi
> 
> Forgot to ask -- how does it look like on the Apache side of things? I
> guess it ends up being a rewrite on the Apache side, which issues a
> redirect?

This is a bit more complicated than it otherwise would be, because I
explicitly wanted to avoid "gitweb" or "cgit" in URLs for whatever
reason, so the same namespace now contains legacy gitweb, cgit, and
http-cloning URLs.

Otherwise I wouldn't have had to use the rewriteengine at all and could
have gotten away with aliases.

<VirtualHost *:80>
ServerName git.zytor.com
ServerAlias git.nasm.us
DocumentRoot /var/lib/git
ErrorLog /var/log/httpd/git/error_log
CustomLog /var/log/httpd/git/access_log combined
RedirectPermanent /var/lib/git /
RedirectPermanent /pub/git /

SetEnv GIT_PROJECT_ROOT /var/lib/git
SetEnv GIT_HTTP_EXPORT_ALL

RewriteEngine on

Alias /cgit-data /usr/share/cgit
ScriptAlias /cgit /var/www/cgi-bin/cgit
ScriptAlias /robots.txt "/var/www/cgi-bin/robots.cgi"

RewriteCond "%{QUERY_STRING}" "^.*p=.*$"
RewriteRule ^/+$ /var/www/cgi-bin/gitweb2cgit.cgi [H=cgi-script]

ScriptAliasMatch ^/+$ /var/www/cgi-bin/cgit

ScriptAliasMatch ^/gitweb.cgi/*$ /var/www/cgi-bin/gitweb2cgit.cgi

AliasMatch ^/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$
/var/lib/git/$1
AliasMatch ^/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$
/var/lib/git/$1
ScriptAliasMatch \
        "(?x)^/(.*/(HEAD | \
                        info/refs | \
                        objects/info/[^/]+ | \
                        git-upload-pack))$" \
        /usr/libexec/git-core/git-http-backend/$1
ScriptAliasMatch ^/+(.*)$ /var/www/cgi-bin/cgit/$1
</VirtualHost>


-- 
Konstantin Ryabitsev
Linux Foundation Collab Projects
Montréal, Québec




More information about the CGit mailing list