the corner office : tech blog

a tech blog, by Colin Pretorius

Converting my CVS repo

I've been using git for a while now, and I'm sold. New pet projects are going into git but I still had a years-old CVS repo, containing dozens upon dozens upon dozens of projects. After a few abortive attempts I managed to get the lot converted. This is how I did it.

I settled on cvs2git which is part of the cvs2svn toolset. A simple apt-get install cvs2svn on Ubuntu. I worked through the instructions on this page, which I'd linked to before.

You really need to run the conversion per module, because if you point cvs2git at your top-level CVSROOT, it'll mix up all tags and commit logs. I created the script below to automate the whole thing. My bash scripting skills are anything but l33t, but it did the job.

The steps:

  1. Create and change into a working directory. The script will create a convert subdirectory, into which all the converted modules will go.

  2. Create a copy of cvs2git-example.options (which a simple locate should find - probably somwhere in /usr/share/doc/cvs2svn/examples) in the working directory. Rename to cvs2git.options (or edit the script appropriately).

  3. In cvs2git.options, find the line containing text

    r'test-data/main-cvsrepos'
    

    and replace with

    os.getenv('CONVERT_MODULE'),
    

    That line tells cvs2git which repo to convert. Using an environment variable allows the bash script to repeatedly export the module to convert.

  4. Dump this script into the working directory:

    #!/bin/bash 
    # script to convert CVS repo to lots of git modules
    
    CFG_FILE=/path/to/working/dir/cvs2git.options
    REPO=/path/to/my/cvsroot
    
    function generate_blob {
    	export CONVERT_MODULE=$REPO/$1
    	cvs2git --options=$CFG_FILE	
    }
    
    function git_from_blob {
    	if [ -d $1 ] 
    	then
    		rm -rf $1
    	fi
    	mkdir convert/$1
    	cd convert/$1
    	git init
    	cat ../../cvs2svn-tmp/git-blob.dat ../../cvs2svn-tmp/git-dump.dat | git fast-import
    	git checkout master
    	cd ../../
    	rm -rf cvs2svn-tmp
    }
    
    function convert {
    	if [ -d cvs2svn-tmp ] 
    	then
    		rm -rf cvs2svn-tmp
    	fi
    	if [ ! -d convert ]
    	then
    		mkdir convert
    	fi
    	generate_blob $1
    	git_from_blob $1
    }
    
    for FILE in `ls $REPO`; 
    do
    	convert $FILE
    done
    

  5. Run the script. The 'Already on master' warnings come from the git checkout master command, which is needed to actually check out code from the newly created git repos. It doesn't seem to have any adverse effects, and if the repo isn't going to be used in-place the git checkout could probably be removed.

All seems fine after the conversion, which is to say all tags and commit logs seem to be in place.

{2010.06.24 15:12}

« YAML

» Lightweight Linux distros