Wednesday, January 30, 2008

Converting a CVS repository to a SubVersion repository

Taking the opportunity of the "extreme makeover" (I am setting up a new IT infrastructure for the new house (e.g. adding NAS, print server, network media players etc) + my old PC did not survive the relocation (HDD died! Arrggg....)), I decided to finally retire my aging CVS repository and move on to SubVersion for good.

Setting up the service in my NAS (DNS-323) is easy enough (besides the small hiccup encountered), converting my 5 year old CVS repository seemed like a daunting task based on the documentation.

The tool to use is cvs2svn, which is basically a bunch of Python scripts that make use of the SVN, CVS and some UNIX utility binaries; In short, a tool developed and used on the UNIX platform primarily. Getting it to work on Windows isn't all that difficult but just alittle tedious. Here are the steps to get it working on a clean Windows XP (i.e. without any of the prerequisite already installed).
  1. Grab Python installer for Windows from here and run the exe on the PC. Once installation is complete, you should get a new folder in your start menu.
  2. Grab the Windows port of the necessary UNIX utility binaries (UnxUtils) from here and unpack the archive file into a directory of your choice. (for me, its C:\UnxUtils)
  3. Grab the cvs2svn package from here and unpack the archive file into a directory of your choice. (for me, its C:\cvs2svn)
  4. Grab the svn package from here (choose the zip file if you do not intend to run the svn server on your PC) and unpack it into a directory of your choice. (for me, its C:\svn-win32-1.4.6\)
  5. *IMPT* Set up your environment path to include the UnxUtils bin directories. (Right click on "My Computer", select "Properties", under "Advanced" tab, click on the "Environment Variables" button, in the popup dialog, scroll the listbox under "System variables" to find the "Path" variable on the left, select it and click on the "Edit" button.) Note that you will need to add both the "\bin" and "\usr\local\wbin" directories in the BEGINNING of your path. This is necessary so that the scripts will call the UNIX versions of sort.exe rather than the one included in your Windows\System32 directory. My path variable looks like this: C:\UnxUtils\bin;C:\UnxUtils\usr\local\wbin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;...
  6. Start a command prompt (Start -> All Programs -> Accessories), cd to your cvs2svn directory, and execute the python exe giving it the cvs2svn script and the necessary arguments (see the cvs2svn docs for details on the arguments). In my case, I did a full conversion with default options hence the command looks like this "c:\Python25\python cvs2svn --svnadmin=c:\svn-win32-1.4.6\bin\svnadmin.exe --svnrepo z:\SvnRepo d:\CodeRepo" Note that this creates a new svn repository at z:\SvnRepo.

The script will take awhile to run if you have a large CVS repository with alot of revisions. In my case, the conversion ended with a revision number hitting well into 4 digits.

Unlike CVS, SVN treats all folders in a repository as part of a common namespace. i.e. the revision numbers, branch and tag names will be shared across all your projects (aka subfolders). I find that rather confusing especially when the projects are entirely unrelated. Hence in my setup, I created separate SVN repository for each of my CVS project. My command then looks like this "c:\Python25\python cvs2svn --svnadmin=c:\svn-win32-1.4.6\bin\svnadmin.exe --svnrepo z:\SvnRepo\projectX d:\CodeRepo\projectX" where projectX are the names of my CVS projects.

As I kept all my SVN repositories under the \SvnRepo directory, I will only need one instance of svnserve on the server side to service all my repositories. In the script (part of the fun_plug svn package), change the variable REPOSITORY to point to this root directory.

Also, you will probably want to modify the svnserve.conf file in each project repository to use the same authentication realm as well as passwd file to keep things simple. (I placed my passwd in the \SvnRepo directory)

On the client side, to access the SVN repositories, use the URL "svn://hostname/projectX/". Note that you will not be able to browse the available projects using the URL "svn://hostname/" (unlike CVS). A small price to pay in exchange for a neater setup IMHO.

Well, that's it for my encounter with cvs2svn as well as my SVN setup. Now on to figuring out the best practices on SVN usage!

No comments: