cgit

From MattWiki
Jump to: navigation, search
< Category:Version Control Software

cgit is fast web interface for the git. cgit has built a cache and is compiled in c so it's very quick.

To start out, download the current version of cgit via git

git clone git://git.zx2c4.com/cgit

Next you need to setup the git submodule

cd cgit
git submodule init
git submodule update

Then compile the software

make

And install it

make install
mkdir -p /var/cache/cgit
chown apache:apache /var/cache/cgit

After you have installed cgit, you will need to setup Apache to run cgit. This is pretty easy, just edit your /etc/httpd/conf/httpd.conf file and add the following for the site you wish to run cgit on.

<Directory "/var/www/code.mattrude.com/">
     AllowOverride None
     Options ExecCGI
     Order allow,deny
     Allow from all
</Directory>

Or you may try my quick setup

mkdir -p /var/src
cd /var/src/
rm -rf cgit
git clone git://hjemli.net/pub/git/cgit
cd cgit
git submodule init
git submodule update
sed -i 's/CGIT_CONFIG = \/etc\/cgitrc/CGIT_CONFIG = \/var\/www\/code.mattrude.com\/cgitrc/g' Makefile
sed -i 's/CGIT_SCRIPT_PATH = \/var\/www\/htdocs\/cgit/CGIT_CONFIG = \/var\/www\/code.mattrude.com\/cgit/g' Makefile
make && make install
mkdir -p /var/cache/cgit
chown nginx:nginx /var/cache/cgit

Or

apt-get -y install gcc make libcurl4-openssl-dev
mkdir -p /var/src && cd /var/src && rm -rf cgit && git clone git://hjemli.net/pub/git/cgit && cd cgit && \
git submodule init && git submodule update && \
sed -i 's/CGIT_CONFIG = \/etc\/cgitrc/CGIT_CONFIG = \/var\/www\/code.mattrude.com\/cgitrc/g' Makefile && \
sed -i 's/CGIT_SCRIPT_PATH = \/var\/www\/htdocs\/cgit/CGIT_SCRIPT_PATH = \/var\/www\/code.mattrude.com/g' Makefile && \
make && make install && mkdir -p /var/cache/cgit

Config file

Once your done setting up cgit in Apache, you may configure cgit by creating a cgitrc file at /etc/cgitrc. Below is the example config file.

EXAMPLE CGITRC FILE
-------------------

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

# Specify some default clone prefixes
clone-prefix=git://foobar.com ssh://foobar.com/pub/git http://foobar.com/git

# Specify the css url
css=/css/cgit.css

# 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

# Add a cgit favicon
favicon=/favicon.ico

# Use a custom logo
logo=/img/mylogo.png

# Enable statistics per week, month and quarter
max-stats=quarter

# Set the title and heading of the repository index page
root-title=foobar.com git repositories

# Set a subheading for the repository index page
root-desc=tracking the foobar development

# Include some more info about foobar.com on the index page
root-readme=/var/www/htdocs/about.html

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

##
## 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

##
## List of repositories.
## PS: Any repositories listed when section is unset will not be
##     displayed under a section heading
## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos')
##      and included like this:
##        include=/etc/cgitrepos
##

repo.url=foo
repo.path=/pub/git/foo.git
repo.desc=the master foo repository
repo.owner=fooman@foobar.com
repo.readme=info/web/about.html

repo.url=bar
repo.path=/pub/git/bar.git
repo.desc=the bars for your foo
repo.owner=barman@foobar.com
repo.readme=info/web/about.html

# The next repositories will be displayed under the 'extras' heading
section=extras

repo.url=baz
repo.path=/pub/git/baz.git
repo.desc=a set of extensions for bar users

repo.url=wiz
repo.path=/pub/git/wiz.git
repo.desc=the wizard of foo

# Add some mirrored repositories
section=mirrors

repo.url=git
repo.path=/pub/git/git.git
repo.desc=the dscm

repo.url=linux
repo.path=/pub/git/linux.git
repo.desc=the kernel

# Disable adhoc downloads of this repo
repo.snapshots=0

# Disable line-counts for this repo
repo.enable-log-linecount=0

# Restrict the max statistics period for this repo
repo.max-stats=month

Configuring CGIT on Apache

<VirtualHost *:9000>
    ServerName code.example.com
    DocumentRoot /var/www/code.example.com
    SetEnv CGIT_CONFIG          /var/www/code.example.com/cgitrc
    Alias /cgit.css             /var/www/code.example.com/cgit.css
    Alias /mattrude.png         /var/www/code.example.com/cgit.png
    Alias /favicon.ico          /var/www/code.example.com/favicon.ico
    Alias /robots.txt           /var/www/code.example.com/robots.txt
    Alias /                     /var/www/code.example.com/cgit.cgi/
    <IfModule mod_expires.c>
      ExpiresActive On
      ExpiresByType image/png "access plus 6 month"
      ExpiresByType image/ico "access plus 6 month"
      ExpiresByType text/css "access plus 6 month"
    </IfModule>
    <IfModule mod_deflate.c>
      SetOutputFilter DEFLATE

      # Don't compress
      SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
      SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary

      #Dealing with proxy servers
      <IfModule mod_headers.c>
        Header append Vary User-Agent
      </IfModule>
    </IfModule>
    <Directory /var/www/code.example.com>
      Options Indexes FollowSymLinks
      Options +ExecCGI
      Order allow,deny
      Allow from all
      AddHandler cgi-script .cgi
      DirectoryIndex cgit.cgi
    </Directory>
</VirtualHost>