Run your own SVN server with WebSVN access and Drupal syntax highlighting

published on March 20, 2009

This is a very short tutorial — it should take you about 15 minutes from start to end — that explains how to run your own SVN server, install WebSVN, which is a web front-end to browse your SVN repository, and apply Drupal syntax highlighting to it.

An example can be seen used to be online at websvn.wimleers.com.

SVN

I run my own SVN repository, because it’s much faster (svn:// FTW), I don’t have size limitations, I can ensure it’s backed up properly and because it’s so easy. I’m going to assume you’ve already installed svn on your (Linux) server.

First, decide where you’re going to put all your SVN repositories. I put mine at /data/svn. Whenever I use the e command, use your favorite editor instead (for me e is an alias for TextMate). Then go through these simple steps:

cd /data/svn
svnadmin create reponame

Create a SVN repository with the name reponame. This creates a certain directory structure.

cd reponame/conf
e svnserve.conf

Control the svnserve daemon behavior for this repository. You probably want to set anon-access = read, or anon-access = none in case it’s a private repository, and auth-access = write. You probably want to uncomment password-db = passwd — this indicates you want to use the file passwd as the database with user/password combinations.

e passwd

Fill out the user/password combinations in this file, as demonstrated in the example.
The configuration part is ready. Now start the svnserve daemon:

svnserve -d -r /data/svn

That’s it! And the nice thing is, that as you add new repositories to /data/svn, they’ll be picked up automatically!

WebSVN

This part is simply amazingly effortless. Assuming you’re using Apache, create the proper virtual host, e.g. websvn.example.com. For me this means that Apache looks for files in /data/www/websvn.example.com.

Now, onto the actual installation (2.1.0 was the latest version of WebSVN at the time of writing, you should replace this by the current version):

cd /data/www/websvn.example.com
svn co http://websvn.tigris.org/svn/websvn/tags/2.1.0 .

Browse to http://websvn.example.com/doc/install.html and there you go, further installation instructions! Most of it is probably even overkill for you. The bases are covered in this tutorial.

chmod 0777 cache

This makes the cache directory writable.

cd include
cp distconfig.php config.php
e config.php

Create your own config.php file, starting from the default one, and edit it. You should add something like (near line 70):

$config->addRepository('Some repository', 'file:///data/svn/somerepository');

Obviously you can add more repositories here!
And near the end of the file, you may want to set this:

$config->expandTabsBy(2);

This sets 2 spaces per tab, instead of the default 8. (Drupal uses 2.)

If you’d like to tweak the interface a little bit, that is, the left sidebar on the front page, you should edit templates/calm/index.tmpl to your liking. It’s plain HTML.

Drupal syntax highlighting for WebSVN

And last but not least: Drupal syntax highlighting1 within WebSVN. This is easier than it looks, thanks to the code included in the excellent GeSHi Filter module for Drupal. We’ll just borrow their Drupal 6 GeSHi language definition file.
You can either apply the patch I’ve attached to this tutorial, or do it yourself, by following the steps below.

Download the drupal6.php file that ships with it and place it in the lib/geshi directory, that same directory contains GeSHi language definition files for all other supported languages.
Now we have to map certain file extensions to use this language definition. For that, we’ll have to hack WebSVN in one file: include/setup.php. Add this to the $extEnscript array (around line 200):

// Drupal support.
'.inc'     => 'drupal6',
'.install' => 'drupal6',
'.module'  => 'drupal6',
'.profile' => 'drupal6',
'.test'    => 'drupal6',

Managing the server

Managing this server is very easy: SVN upgrades should come with your operating system’s packet manager.
Your changes to WebSVN can be stored through a simple patch:

cd /data/www/websvn.example.com
svn add include/config.php
svn add lib/geshi/drupal6.php
svn diff > mywebsvn.patch

Updating WebSVN is as simple as checking out a newer version from the SVN repository.

Update on February 23, 2010

I stopped using WebSVN because it was generating caches of multiple gigabytes in size. Which obviously sucks — it’s understandable, but they should offer the option to set a maximum cache size, or a cache TTL.


  1. Including links to api.drupal.org↩︎

Comments

Anonymous's picture

Anonymous

It’s not clear for me where i have to put the drupal6.php file. Where is the lib/geshi directory exactly? Is it in the websvn root folder?

Or do i have install geshi in websvn first?

Wim Leers's picture

Wim Leers

The lib/geshi directory is indeed in the websvn root folder!

Anonymous's picture

Anonymous

Thanks for you quick reply. I had websvn 2.0 installed on ubuntu and that version doesn’t support geshi out of the box. websvn 2.1.0 and greater provide supports for Geshi engine.

Now i have installed websvn 2.3.0 and php-geshi package for ubuntu.

The drupal6.php file i have to put into the folder /usr/share/php-geshi/geshi/ .

The new drupal extensions goes to the new $extGeshi array up to line 255.

The new syntax looks like this: 'drupal6' => array('module'), 'drupal6' => array('info'),

Now it looks fine with Geshi!

Anonymous's picture

Anonymous

It’s better to put all extensions into the array ‘drupal6’:

// Drupal support. 'drupal6' => array('module', 'info', 'inc', 'install', 'profile', 'test'),