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 usingcvs2svn
, Disable CVS accounts (could t 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 Modulewooyay
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 intags/
, Branches are inbranches/
, And head istrunk
.
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 calledv1_2_3
Instead1.2.3
. And I don't like that. Here is an example of what I wowould 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 onlytrunk/
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. Mysvn_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 wocould be the contents of/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 runsvn_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 currentsvn_cvsinject
Features:
- Support for file creation and Removal
- Support for Directory Creation and Removal
- Support for simultaneous commits in different branches
- Support for Branch aliases
However, it also has the following current limitations:
- No support for new branches
- No user mapping when run from
svnserve
(But the user is mentioned in the commit log)
- Concurrent CILS may break things (use locks)
- Poor error handling
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 submit upted, You Can reinject every SVN commit by restoring your backuped CVS tree and callingsvn_cvsinject
Again For every revision since you usedcvs2svn