Skip to content

Instantly share code, notes, and snippets.

@Gumnos
Forked from thwarted/rcs2git
Created February 12, 2012 03:51
Show Gist options
  • Save Gumnos/1806119 to your computer and use it in GitHub Desktop.
Save Gumnos/1806119 to your computer and use it in GitHub Desktop.
rcs2git, quick and dirty brute force
#!/bin/bash
email_domain=example.com
export email_domain
# so nothing in the environment comes through
unset GIT_AUTHOR_EMAIL
unset GIT_AUTHOR_DATE
unset GIT_AUTHOR_NAME
unset GIT_COMMITTER_NAME
unset GIT_COMMITTER_EMAIL
export GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE GIT_AUTHOR_NAME GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
if [ -z "$*" ]; then
echo "Usage: $0 *,v" >&2
exit 0
fi
set -e
#set -x
if [ -d .git ]; then
echo ".git dir already exists! (cowardly bailing)"
exit 0
else
git init
fi
# brute force, doesn't support tags or anything other than plain check-ins of individual files
# kinda sloppy in general
# first we get all the revisions and sort by edit date, then sort that to check them in the right order
(
for rcsfile in "$@" ; do
rcsfile="$( echo "$rcsfile" | sed -e 's/,v$//;' )"
echo "$rcsfile"
for rev in $( rlog $rcsfile | awk '/^revision/{ print $2 }' | awk -F. '{print $2}' | sort -n ); do
loginfo="$( rlog -r1.$rev $rcsfile | grep '^date: ' | tr ';' '\n' | sed -e 's/^ \+//;' )"
# 2010/03/05 16:09:26
# 2005-04-07T22:13:13
commitdate="$( echo "$loginfo" | grep date: | sed -e 's/^[^:]\+: //;' | sed -e 's/^ //; s!/!-!g; s/ /T/g;' )"
GIT_AUTHOR_DATE="$commitdate"
commitauthor="$( echo "$loginfo" | grep author: | sed -e 's/^[^:]\+: //;' )"
EMAIL="$commitauthor@$email_domain"
GIT_AUTHOR_NAME="$commitauthor"
/bin/echo -e "$GIT_AUTHOR_DATE\t$rev\t$EMAIL\t$GIT_AUTHOR_NAME\t$rcsfile"
done
done
) | sort | while read GIT_AUTHOR_DATE rev EMAIL GIT_AUTHOR_NAME rcsfile; do
GIT_COMMITER_NAME=$GIT_AUTHOR_NAME
export GIT_AUTHOR_DATE rev EMAIL GIT_AUTHOR_NAME rcsfile GIT_COMMITTER_NAME
co -r1.$rev $rcsfile
git add $rcsfile
logmsg="$( rlog -r1.$rev $rcsfile | perl -e '$_=<> until (m/^date:.+author: /); while ($_=<>) { print $_ if !m/^=====/ }' )"
git commit -m "$logmsg"
echo "committed rev 1.$rev of $rcsfile" >&2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment