Switch from gitweb to cgit

I switched my git repository browsing tool from gitweb to cgit.

I haven’t found any really working option to enable caching in gitweb. I have some repositories which are really large. At the moment, one call to the gitweb main (project) page costs a lot of time because the git call to get the latest commit time git for-each-ref —format=’%(committer)’ —sort=-committerdate —count=1 refs/heads

is really time expensive.

First I deleted this section in the gitweb.cgi script. It was much faster, but the possibility to see when the last changes in one repo was done is a must have option to me.

I hosted both. One url for the fast gitweb cgi script and one for the slow cgi script. This was not really a good option to me. So I had a look at alternatives to gitweb and I found cgit.

I describe a short way to host cgit on apache webserver.

[TOC]

Requirements

  • git (I used Version 1.7.1)
  • apache2 (available as debian/SuSE packages)
  • cgit (available as debian/SuSE packages)

Apache config

If cgit is installed with a debian or SuSE package, all files are on right position. I describe the configuration on SuSE (11.3).

vhosts file

First of all create a vhosts file. I called it repositories.conf and it is located at /etc/apache2/vhosts.d/.

<VirtualHost *:80>

    DirectoryIndex cgit.cgi

    Alias /cgit.png /srv/www/htdocs/cgit/cgit.png
    Alias /cgit.css /srv/www/htdocs/cgit/cgit.css
    <Directory "/srv/www/cgi-bin/cgit">
        AllowOverride none
        Options FollowSymlinks ExecCGI
        Allow from all
        Order allow,deny

        <Files cgit.cgi>
            SetHandler cgi-script
        </Files>

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^.* /cgit.cgi/$0 [L,PT]
    </Directory>

    <Directory "/srv/www/git">
        Options FollowSymlinks Indexes
        Allow from all
        AllowOverride none
        Order allow,deny
    </Directory>
</VirtualHost>

Rewrite gitweb URL

I have some links in my bug tracking tool Trac to gitweb commitdiffs. I don’t want to change this old urls. So I have to rewrite this urls to the new cgit one.

Therefore, replace the RewriteRule ^.* /cgit.cgi/$0 [L,PT] with RewriteRule ^(.*)/commitdiff/(.*)$ /cgit\.cgi/$1/commit/?id=$2

load required modules and vhosts

I need the apache module rewrite enabled. To enable it just call a2enmod rewrite.

After that, we have to reload apache: service apache2 reload.

cgit config file

Now I created a cgit config file. It is located at /etc/cgitrc

# Enable caching of up to
1000 output entriess
cache-size=1000

# Specify some default clone prefixes
clone-prefix=http://USER@host/git/repo.git

# Specify the css url
css=/cgit.css

# Specify the logo url
logo=/cgit.png

# Show extra links for each repository on the index page
enable-index-links=1

# Show number of affected files per commit on the log pages
enable-log-filecount=1

# Show number of added/removed lines per commit on the log pages
enable-log-linecount=1

# Set the title and heading of the repository index page
root-title=My git repositories
root-desc=containing all git repositories

# Allow download of tar.gz, tar.bz2 and zip-files
snapshots=tar.gz

scan-path=/srv/www/git

source-filter=/usr/lib/cgit/filters/syntax-highlighting.sh

remove-suffix=1

##
## List of common mimetypes
##
mimetype.git=image/git
mimetype.html=text/html
mimetype.jpg=image/jpeg
mimetype.jpeg=image/jpeg
mimetype.pdf=application/pdf
mimetype.png=image/png
mimetype.svg=image/svg+xml

We don’t have to enable the cgitrc explicit. It is loaded automatically by cgit.

Update: The configuration files are now available on GitHub.

comments powered by Disqus