about me

projects

MPEG & DVD

doc

leisure

HOWTO: smooth CVS to SVN migration (and back again)

This page explains how I migrated the VideoLAN CVS repositories to Subversion while still allowing anonymous CVS access for users who did not want to move to Subversion. If you are a CVS user and have not yet fallen in love with Subversion, I suggest you have a look at this excellent project. In fact, I recommend to be familiar with Subversion before reading this document, because I may have missed important things.

The idea is to migrate the CVS repository to a Subversion repository using cvs2svn, disable CVS accounts (except read-only accounts such as anonymous) and set up post-commit hooks to replicate SVN commits back to the CVS repository.

First step: cvs2svn

Here are the preparatory steps to migrate a CVS module wooyay from the CVS root /cvs/stuff to a new SVN repository /svn/wooyay:

$ svnadmin create /svn/wooyay
$ cvs2svn -s /svn/wooyay /cvs/stuff/wooyay
$ svn ls file:///svn/wooyay
branches/
tags/
trunk/
$

That’s all! Your SVN repository is created. The default layout is a bit special but quite handy: tags are in tags/, branches are in branches/, and HEAD is trunk.

Don’t forget to backup your old CVS tree! It might be useful if something ever gets wrong.

Repository cleaning

Now that your repository is created, you can use Subversion’s magical powers to do whatever you want to the repository, such as removing and renaming branches or tags. These steps are not mandatory but you might find them convenient.

CVS branch names cannot start with a digit or contain periods, and you end up with branches called v1_2_3 instead of 1.2.3. And I don’t like that. Here is an example of what I would do:

$ svn ls file:///svn/wooyay/branches
test/
v1_0/
v2_0/
$ svn rm file:///svn/wooyay/branches/test -m "removed branch"
$ svn mv file:///svn/wooyay/branches/v1_0 file:///svn/wooyay/branches/1.0 -m "renamed branch"
$ svn mv file:///svn/wooyay/branches/v2_0 file:///svn/wooyay/branches/2.0 -m "renamed branch"
$ svn ls file:///svn/wooyay/branches
1.0/
2.0/
$

I also like to import .cvsignore files to Subversion properties and set the "Id" keyword properties for files containing the "$Id:" special string. If your repository is big, you might want to do this change only for trunk/ and the still active branches.

$ svn checkout file:///svn/wooyay/trunk workingdir
$ cd workingdir/
$ find -name .cvsignore | while read file; do
    svn propset svn:ignore "`cat "$file"`" "`echo "$file" | sed 's,/[^/]*$,,'`"
  done

$ find . -type f -a '(' -path '*/.*' -prune -o -print ')' | while read file; do
    if grep -q '\$Id:' "$file" && ! svn propget svn:keywords "$file" | grep -q '^Id$'; then svn propset svn:keywords Id "$file"; fi
  done

$ svn commit -m "imported svn:ignore and svn:keywords properties"
$

The post-commit hook

This is the important part. My svn_cvsinject script can be used to reinject SVN commits into the old CVS directory. Use option -r to specify the revision to reinject, and -a to do branch aliases. In our example, this would be the contents of the /svn/wooyay/hooks/post-commit file:

#!/bin/sh
REPOS="$1"
REV="$2"
svn_maillog "$REPOS" "$REV" "svn@localhost" "sam@localhost"
svn_cvsinject -r "$REV" "$REPOS" "/cvs/stuff/wooyay" \
    -a "1.0/v1_0" -a "2.0/v2_0" &
exit 0

It is advisable to run svn_cvsinject in the background because it can take a long time to finish. Also, make sure that all users with commit rights (including the user svnserve might run as) have write permissions on the CVS repository.

Here are the current svn_cvsinject features:

However, it also has the following current limitations:

Conclusion

It works for me (tm), but I’d be happy to learn of other successful installations. And please tell me of failures as well, so that I can fix bugs!

If your CVS repository ever gets corrupted, you can reinject every SVN commit by restoring your backuped CVS tree and calling svn_cvsinject again for every revision since you used cvs2svn.