Skip to content

Instantly share code, notes, and snippets.

@konfou konfou/sf-cvs2git.sh
Last active May 16, 2017

Embed
What would you like to do?
cvs.sourceforge-to-git
#!/usr/bin/env bash
#
# Convert a Sourceforge's CVS repo to Git.
# depends
type -p rsync >/dev/null || exit 3
type -p cvs2git >/dev/null || exit 3
# trap SIGINT
trap 'trap - INT; kill -s INT "$$"' INT
PROJ=$1 # project name
RSD=$1-cvs # rsync destination
SRC=${RSD} # cvs2git source (cvs repo)
MOD=${PROJ} # cvs module
DST=$1-git # cvs2git destination (git repo)
# cvs2git options file
OPTFILE=cvs2git.options
# set to empty value to use the following
# cvs2git options
TMP=/tmp/cvs2git-tmp
BLOB=git-blob.dat
DUMP=git-dump.dat
USER=cvs2git
backup-sf-cvs() {
rsync -av rsync://${PROJ}.cvs.sourceforge.net/cvsroot/${PROJ}/\* ${RSD}
}
set-options() {
local path_to_cvs_repo=$(readlink -f ${SRC}/${MOD})
cp /usr/share/doc/cvs2svn/examples/cvs2git-example.options ${OPTFILE}
sed -i "s~cvs2svn <admin@example.com>~${USER} <admin@example.com>~" ${OPTFILE}
sed -i "s~cvs2svn-tmp~${TMP}~" ${OPTFILE}
sed -i "s~cvs2svn-tmp/git-blob.dat~${TMP}/${BLOB}~" ${OPTFILE}
sed -i "s~git-dump.dat~${DUMP}~" ${OPTFILE}
sed -i "s~test-data/main-cvsrepos~${path_to_cvs_repo}~" ${OPTFILE}
vi ${OPTFILE} # extra edits like author_transforms
}
cvs2git-wrap() {
if [[ ! -z ${OPTFILE} ]]; then
cvs2git --options=${OPTFILE}
else
cvs2git \
--tmpdir=${TMP} \
--blobfile=${TMP}/${BLOB} \
--dumpfile=${TMP}/${DUMP} \
--username=${USER} \
${SRC}
fi
}
git-wrap() {
cd ${DST}
git init
cat ${TMP}/${BLOB} ${TMP}/${DUMP} | git fast-import
git checkout
git gc --prune=now
git repack -adf
}
usage() {
echo "Usage: $(basename $0) [project name]"
exit 1
}
main() {
mkdir -p ${TMP} ${DST}
backup-sf-cvs
[[ ! -z ${OPTFILE} ]] && set-options
cvs2git-wrap
git-wrap
rm -r ${TMP}
}
[[ -z "${PROJ}" ]] && usage || main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.