Skip to content

Instantly share code, notes, and snippets.

@roytam1
Created October 17, 2021 03:04
Show Gist options
  • Save roytam1/d9720951780350b2f13cc56be1eb2117 to your computer and use it in GitHub Desktop.
Save roytam1/d9720951780350b2f13cc56be1eb2117 to your computer and use it in GitHub Desktop.
git-cvsmod2subdir.sh mod
#!/bin/sh
###########################################################
# Script to import several CVS modules as subdirectories
# into a git repository. If necessary create the repository
# with git init, and perform a an initial commit committing
# something before running this script. git seems reluctant
# to merge into a completely empty repository.
#
# Thanks to all the people who have placed useful git
# documentation on the web before me.
if [ -d .git ]
then
# We are in a git repo, note the working directory.
REPO_DIR=$(pwd)
else
echo "No Git repo detected, please run in root of repo working tree."
exit 1
fi;
# Loop through command line arguments, each should be a CVS module
for CVS_MODULE in $@
do
# Put the module in an environment variable so git filter-branch sees it
export __MODULE_AND_SUBDIR=$CVS_MODULE
# Make a temporary repo for the operation
mkdir /tmp/git_cvsmod2subdir_$__MODULE_AND_SUBDIR
cd /tmp/git_cvsmod2subdir_$__MODULE_AND_SUBDIR
# Perform CVS module import to repo, straight to the master branch
# NOTE: Modify the CVS repository location to match your setup.
nice git cvsimport -o master -v -d $CVSROOT $__MODULE_AND_SUBDIR
# Rewrite history and put the module in a subdir named after the module
nice git filter-branch -f --index-filter \
'git ls-files -s | sed "s!\t!&$__MODULE_AND_SUBDIR/!" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
if [ -f $GIT_INDEX_FILE.new ] ; then mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE ; fi' HEAD
# Go to original repo, fetch imported CVS module as a branch, and merge
cd $REPO_DIR
nice git fetch /tmp/git_cvsmod2subdir_$__MODULE_AND_SUBDIR master:cvsmodule-$__MODULE_AND_SUBDIR
nice git merge cvsmodule-$__MODULE_AND_SUBDIR
# Clean up the temporary repo
rm -rf /tmp/git_cvsmod2subdir_$__MODULE_AND_SUBDIR
done
@roytam1
Copy link
Author

roytam1 commented Oct 17, 2021

to use, you have to set CVSROOT environment that points to path of your CVS local tree that contains CVSROOT directory, and run in a git-inited directory with specified cvs modules. for example:

env CVSROOT=$(dirname `pwd`)/heirloom-cvs sh ../git-cvsmod2subdir.sh heirloom heirloom-devtools heirloom-doctools heirloom-pkgtools heirloom-sh

and different modules will sit in their own branches. you may want to merge them together with --allow-unrelated-histories switch, for example:

git merge cvsmodule-heirloom-sh --allow-unrelated-histories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment