All pastes #254141 Raw Edit

vsu

public shellscript v1 · immutable
#254141 ·published 2006-11-21 15:26 UTC
rendered paste body
#!/bin/sh -euPROG="${0##*/}"fatal(){	printf %s\\n "$PROG: $*" >&2	exit 1}workdir=exit_handler(){	local rc=$?	trap - EXIT	[ -z "$workdir" ] || rm -rf "$workdir"	exit $rc}signal_handler(){	echo "$PROG: Interrupted" >&2	exit 1}trap exit_handler EXITtrap signal_handler SIGHUP SIGPIPE SIGINT SIGTERM SIGQUITworkdir=`mktemp -td cvs2git.XXXXXXXXXX` ||	fatal "failed to create working directory"rewrite_head(){	local head="$1" && shift	local new_head="$1" && shift	git checkout "old/$head"	cg-admin-rewritehist \		--msg-filter 'perl -0777 -pe "s/^\\n+//s"' \		--commit-filter '		if { [ "$#" = 3 ] &&			[ -z "$(git-diff-tree "$GIT_COMMIT^1" "$GIT_COMMIT")" ]		} || [ "$GIT_AUTHOR_NAME" = "cvs2svn" ]		then			shift			while [ -n "$1" ]; do				shift; echo "$1"; shift			done		elif [ "$#" = 1 ] &&			[ "$1" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904 ]		then			shift		else			msg="$(mktemp -t rewrite.XXXXXXXXXX)"			cat >"$msg"			if grep -qs "file .* was added on branch .* on " "$msg"			then				shift				while [ -n "$1" ]; do					shift; echo "$1"; shift				done			else				git-commit-tree "$@" <"$msg"			fi			rm -f "$msg"		fi		' "$new_head"}[ "$#" = 2 ] || fatal "usage: $PROG <cvs-repo> <git-repo>"cvs_repo="$1"git_repo="$2"[ -d "$cvs_repo" ] || fatal "CVS repository '$cvs_repo' not found"[ -e "$git_repo" ] && fatal "GIT repository '$git_repo' already exists" ||:svn_repo="$workdir/svn"authors="$(readlink -ev Authors)" ||	fatal "Authors file not found"cvs2svn -s "$svn_repo" --username=cvs2svn --keywords-off --encoding=utf-8 \	"$cvs_repo"mkdir -p "$git_repo"cd "$git_repo"git-init-dbgit-svn multi-init -b branches --no-metadata -A "$authors" \	file://"$svn_repo"git-svn multi-fetch --no-metadata -A "$authors"rm -rf "$svn_repo"rm -f .git/refs/heads/mastermv .git/refs/remotes .git/refs/heads/oldmv .git/refs/heads/old/{trunk,master}for head in `ls -1 .git/refs/heads/old`; do	new_head="$(echo "$head" | sed 's/_/./g')" 	case "$new_head" in		std-2.4.22-alt12.kdb)	continue 			;;		std-2.4.22-patches)	new_head='alt-linux-2.3'	;;		Master-2.4)		new_head='alt-linux-2.4'	;;		branch-3.0)		new_head='alt-linux-3.0'	;;	esac	rewrite_head "$head" "$new_head"donegit checkout masterrm -rf .git/refs/heads/oldgit repack -a -d -l -fgit prune