blog dds

2012.08.07

Importing an RCS Project into Git

RCS stands for Revision Control System. You may have never heard it, because it's more than a quarter-century old; a paper describing it was published in 1985. Although its commands are still available in most Unix distributions and it's one of the easiest systems to use in a single-user scenario, it is clearly showing its age when compared to more modern systems. Here is how to move an existing project managed with RCS to the 21st century and Git, while preserving all its history.

In brief what you do is to create a CVS-like structure of the project, and then use the (confusingly named) cvs2svn command to export that into a format that Git can read. Before you start this process back up the original directory, since this process is destructive. Believe me, you will need the backup. More than once.

First, go into the project's directory and convert any very old RCS files that don't end with ",v" into the modern RCS file naming convention. This might be required if you're dealing with an MS-DOS era RCS repository.

find . -type f |
fgrep RCS/ |
fgrep -v ,v |
sed 's/.*/mv "&" "&,v"/'  |
sh

Then, check-in any files that are not under version control, by creating (if needed) the appropriate RCS directories and running RCS ci for each file.

find . -type f |
grep -v /RCS/ |
while read f
do
	if ! [ -r "RCS/$f,v" ]
	then
		mkdir -p `dirname "$f"`/RCS
		date=`stat -c %y "$f"`
		ci -u -d"$date" -t-'Checking before Git import' "$f"
	fi
done

Your next step involves creating a mirror structure of the RCS repository files that looks like a CVS repo.

# Create CVS-like repo
mkdir ../project.CVS

# Create destination directories
find . -type d -name RCS |
sed 's,/RCS,,;s,^,mkdir -p "../project.CVS/,;s,$,",' |
sh

# Move the files to the CVS-like repo
find . -type d -name RCS |
sed 's,.*,mv "&"/* ../project.CVS/"&",;s,/RCS$,/,'
| sh

Now you can convert the CVS-like repo into the so-called fast import format, which you can import into Git. Go to the cvs2svn project directory and run

python cvs2git --use-rcs --username yourname \
  --blobfile /tmp/b2x.blob --dumpfile /tmp/b2x.dump .../project.CVS
At this step you might want to transform the author names and add their email addresses. To do that you need to setup a cvs2git.options file; consult the cvs2git-example.options example file provided with cvs2svn.

Finally, create a new Git repository and import the files into it.

mkdir project.git
cd project.git
git init
cat /tmp/b2x.blob /tmp/b2x.dump | git fast-import
git reset --hard HEAD

Verify that the history and the contents of the new repo match the original. Mission accomplished!

Read and post comments, or share through   


Creative Commons License Last modified: Tuesday, August 7, 2012 7:19 pm
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.