Setting up a subversion repository in 5 min.

I am currently working on some python coding and since the number of files is getting quite large and being more than one developer on the project it became clear that I need to do some revision control. Eventhough de-centralised revison control is the new black I wanted a centralised solution so everybody could check out agains the server.

Setting up the subversion
First I create the repository

tjansson@ikos:~$ svnadmin create subversion --fs-type fsfs

Then I import the files residing the folder ~/dpy into the repository.

tjansson@ikos:~$ svn import dpy/ file:///home/gfy-1/tjansson/subversion/dpy -m "Initial import"

Now the folder ~/dpy isn’t used anymore as all the files are inside the repository in a database.

All the users I need to colaborate with is users on the same Linux server. Eventhough I really wanted to have grainular control of the user access to the repository this wasn’t possible since the university server doesn’t have ACL (Acces control lists) enabled. The ugly solution is to make the directory writable by all users on the system – which isn’t to bad since I trust the users at this university:

tjansson@ikos:~$ tjansson@ikos:~$chmod -R 777 subversion/

For more information on the subject of permission and repositories:
Supporting Multiple Repository Access Methods

An example of daily usage
Every user that has to work with the files needs to create a working copy and for the sake of the argument I will do the steps as the imaginary user hermann. First hermann get a copy of the files from the repository.

hermann@ikos:~$ svn co file:///home/gfy-1/tjansson/subversion
A  dpy/
Checked out revision 12.

Now hermann has a woking copy. Now he would like to start working with the files, so first he makes sure that he has the lastest copy of the files:

hermann@ikos:~/dpy$ svn update
At revision 12.

Now hermann starts editing the files and when he whishes to commit his changes he uses the command:

hermann@ikos:~/dpy$ svn commit -m "I have change the cheese class to allow emmentaler"

Two thing are important at this point. There should always be a comment and the comment should be informative – this makes it easy to go back to a former change. The second is to commit every time a change has been done – this makes it easy to find points of errors.

The last basic commands is to add a file:

hermann@ikos:~/dpy$ svn add baconcheese.txt
hermann@ikos:~/dpy$ svn commit -m "This cheese is important"

and remove a file:

hermann@ikos:~/dpy$ svn remove ham.txt
hermann@ikos:~/dpy$ svn commit -m "Ham is not cheese and shouldn't be a part of the project."

Finally It can be nice to see what happened since the last update or commit:

hermann@ikos:~/dpy$ svn log

There are lots off more advanced command such as branching, merging etc. and they are described here:
Version Control with Subversion (Official free book)

Remote acces through SSH
Say I wish to work on the files from home. I can do this through SSH:

tjansson@dirac:~>svn co svn+ssh:// password:
A  dpy/
Checked out revision 12.

Adding $Id$ to the files
One of the great thing when using revision control is to be able to keep track on who altered the file and when. This can be done by adding a small tag, $Id$ to the the files. First the files should be prepared to for this by using the following command. In this command I only do this to the python files:

hermann@ikos:~/dpy$ svn propset svn:keywords "Id" *.py

And in the top of the python files I add the line # $Id$ like this:

# $Id$

which is expanded after the next commit:

# $Id: 8 2008-03-11 15:10:18Z tjansson $

Visual svn clients
Even though it is great to know the basic commands it can be nice to use a graphical user interface to manage SVN. On linux system I use kdesvn which is really nice.

Using SVN on Microsofts Windows
On Windows the standards seems to be a open source explorer plugin called TortoiseSVN which is easy to install. First thing to do is download the latestes version from:
and install the program. Since the program is a explorer plugin Windows needs to be restarted before use.

After a restart the first thing to do is to checkout the repository which is done by creating a folder and right-clicking the folder as shown in this picture.

Now a interface should appear where a line like this should be inserted as seen in the image:


And after a lot password typing – 3 times in my case the locale folder should be updated. The actions as doing a commit or update of the local folder can now be acces on the folder in question by right-clicking the folder as seen in this image

Version Control with Subversion (Official book)
Subversion : automating svn:keywords
How to create a svn repository
SVN resources

Only registered users can comment.

  1. If you should ever encounter problems with SVN like this:

    tjansson@ikos:~/pyGravsoft$svn update
    svn: Unable to open an ra_local session to URL
    svn: Unable to open repository 'file:///home/gfy-1/tjansson/subversion/pyGravsoft'
    svn: Berkeley DB error while opening environment for filesystem /home/gfy-1/tjansson/subversion/pyGravsoft/db:
    DB_RUNRECOVERY: Fatal error, run database recovery
    svn: bdb: PANIC: fatal region error detected; run recovery

    The solution is to run recover which rewinds the repository back to a consistent state

    tjansson@ikos:~/subversion$svnadmin recover pyGravsoft/
  2. After experincing recurrent events of problems with commit and update problems using the Berkley database I converted the repository to the FSFS file based system instead.

    The conversion was surprisingly simple. First I moved the old repository to the name subversionOLD and then I created the new one with

    svnadmin create subversion --fs-type fsfs

    and finally I made a dump/load to get the data into the new repository

    svnadmin dump subversionOLD -q | svnadmin load subversion

    The FAQ post from:
    An article about FSFS:

  3. Another really useful option is

    svn propset svn:eol-style native *.py

    this makes end-of-line character to change with the operating system you check out in. So if you are a Linux developer and needs to test changes in Windows – the eol is automatically corrected. 🙂

  4. In the case that the several users should use the same repository residing in some user directory a group should be set up. First I create the subversion project:

    tjansson@nobel:~$ mkdir subversion/
    tjansson@nobel:~$ cd subversion/
    tjansson@nobel:~/subversion$ svnadmin create nobel --fs-type fsfs
    tjansson@nobel:~/subversion$ svn import /home/tjansson/nobel/ file:///home/tjansson/subversion/nobel/

    Now I create a group. Add some members to the group and sets me as the administrator of the group. I then change the ownership of the folder and give the group rights in this folder.

    root@nobel:~$ groupadd svn-nobel
    root@nobel:~# gpasswd -A tjansson -M member1,member2 svn-nobel
    root@nobel:~# chgrp -R svn-nobel /home/tjansson/subversion/
    root@nobel:~# chmod -R 2775 /home/tjansson/subversion/

    The group administrator can add a member with:

    tjansson@nobel:~$ gpasswd -a member svn-nobel

    The group administrator can delete a member with:

    tjansson@nobel:~$ gpasswd -d member svn-nobel

Leave a Reply