If you’re like me, you have Subversion repositories everywhere. Every project you do starts with an svnadmin create, followed by an svn checkout. If you’re more organised than me, you might even have a shell script to do that for you (I wish I was more organised than me).
If you’re not like me, well damnit, you should be! It’s so easy to create a new svn repository and it saves you from screwing up your work (or in extreme cases deleting it entirely – yes this has happened to me, and a friend too).
(Apologies to those higher beings who’ve moved on from Subversion to even funkier revision systems).
But I’m not here to preach about Subversion. I’m here to show you a neat app you can install to make your life easier, assuming you already use Subversion.
ViewVC is a nifty Python-based web app which lets you browse your files, logs, diffs and history using a web browser. It’s designed for use in large team projects, and it’s automatically active on all SourceForge projects. (Example). But I’m going to show you how to set it up for your own personal projects on your localhost.
How to do it
First, you need Apache, Subversion, and ViewVC. Of course if you have Ubuntu, this is ridiculously easy:
sudo apt-get install apache2 subversion viewvc
If you’re not on Ubuntu, then you’re on your own for these steps. (ViewVC’s documentation is in the INSTALL file inside the source package itself).
Next, edit the ViewVC configuration file. By default, it’s /etc/viewvc/viewvc.conf.
- Comment-out cvs_roots and svn_roots.
- Uncomment root_parents and set it to “/some/path : svn”. eg: “root_parents = /home/matt/repos : svn”
- Set address to your email address (not that you need to know your own email address, but you have to put something there).
- Set root_as_url_component = 1. Makes nicer URLs (try it without it and see the difference).
That’s it! Now create the directory you referenced above, (eg. /home/matt/repos), and all you need to do is chuck your repositories in there.
Of course, what you really do is keep them wherever you like them, and make symlinks to them. This is quite easy. Whenever you make a new repository (say you make a repository in /home/matt/src/svn/awesome), link it like this:
ln -fs /home/matt/src/svn/awesome /home/matt/repos
(You can delete the link at any time as if it was a regular file).
Now, point your browser to http://localhost/cgi-bin/viewvc.cgi (the default place it is installed), and you will be able to browse all the repositories.
As a last step, we can make that URL a bit nicer. I’d like a URL like this: http://svn.localhost/.
You need to find your Apache config file. On Ubuntu, this is located in /etc/apache2/sites-enabled/000-default. Edit the file and add this to the very bottom:
<VirtualHost *> ServerName svn.localhost ScriptAlias / "/usr/lib/cgi-bin/viewvc.cgi/" </VirtualHost>
This sets it so if you access your localhost using the domain name svn.localhost, it will override whatever else you have set up to use ViewVC. The last thing you need to do is get svn.localhost to DNS-lookup to 127.0.0.1 (or the browser won’t be able to find the web server). To do this, edit the file /etc/hosts. Add the following line, near the top:
Now you can bookmark http://svn.localhost/, for a quick and convenient way to browse all of your Subversion repositories. Excellent!