ViewVC – Your personal Subversion viewer

In Version control on June 10, 2008 by Matt Giuca Tagged: ,

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.

Bonus step

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/"

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 (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:    svn.localhost

Now you can bookmark http://svn.localhost/, for a quick and convenient way to browse all of your Subversion repositories. Excellent!


6 Responses to “ViewVC – Your personal Subversion viewer”

  1. That does sound easy, except for one small problem: I don’t have superuser access to the host on which my subversion repositories reside. Is it possible to use this tool with remote (svn+ssh://…) repositories?

  2. Hmm, I think it requires a path on the local file system. So the only way to do that might be to somehow mount the remote filesystem on your local filesystem.

  3. Just a tip:
    ScriptAlias /svn/ “/usr/lib/cgi-bin/viewvc.cgi/”
    ScriptAlias /svn “/usr/lib/cgi-bin/viewvc.cgi/”
    <Location /svn>
    Options +ExecCGI
    To the existing VirtualHosts, will allow you to access http://localhost/svn or http://localhost/svn/ without having to create an entire new VirtualHost. The new VirtualHost you suggested conflicts with my *:80 and *:443 http and https hosts. (Going to http://localhost/test gaves an error from the SVN The root “test” is unknown. If you believe the value is correct, then please double-check your configuration. instead of going to the folder in /var/www/test.) Using the snippet above was easier than reconfiguring the entire list of virtual hosts. 😀

    Thanks for the article!

  4. Cheers for that Mr. Blade.

    Yes, if my suggestion doesn’t work for you, that’s a good fallback.

  5. nice post… thanks dude…

    • hi friends, if i want add one more directory contains repos, the whts the change i hav to do in viewvc.conf and httpd.conf. Thanks in advance

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: