Index: user/uqs/git_conv/git_conv =================================================================== --- user/uqs/git_conv/git_conv (revision 290652) +++ user/uqs/git_conv/git_conv (revision 290653) @@ -1,141 +1,158 @@ #!/bin/sh # # Repository creation and setup # # Simple for svn2git repos, need to run against local paths, using rules files in ~git/*.rules # - First svn2git run will create target git repo, then # - git config --global push.default matching # - git remote add github github.com:freebsd/freebsd.git # - git config --add remote.github.push '+refs/heads/master:refs/heads/master' # - git config --add remote.github.push '+refs/heads/stable/*:refs/heads/stable/*' # - git config --add remote.github.push '+refs/heads/projects/*:refs/heads/projects/*' # - git config --add remote.github.push '+refs/notes/*:refs/notes/*' # - etc. # - touch freebsd-base.git/git-daemon-export-ok # - svn2git/svn-all-fast-export --rules ~git/freebsd-base.rules --add-metadata-notes --identity-domain FreeBSD.org /home/svn/base # - git push github # done. Analog steps needed for doc and ports. # # For git-svn it's a bit more involved. We use separate working dirs, but push to the same destination repo. # - git svn init -Thead -rewrite-root=svn+ssh://svn.freebsd.org/base file:///home/svn/base src-head.git # - cd src-head.git # - git svn fetch -r 0:1000 # - git config --global push.default matching # - git remote add github github.com:freebsd/freebsd.git # - git config --add remote.github.push '+refs/remotes/trunk:refs/heads/svn_head' # - git svn rebase # - git push github : ${BASE=/home/git} : ${RULES_DIR=${BASE}} : ${SVN2GIT=/usr/local/bin/svn2git} : ${SRC_REPO=/home/svn/base} : ${DOC_REPO=/home/svn/doc} : ${PORTS_REPO=/home/svn/ports} +usage() +{ + exit 1 +} + +do_gitsvn=1 +do_svn2git=1 +run_local= + +# These options are ass-backwards, but default should be to do both. +while getopts "gls" OPT; do + case "$OPT" in + g) + do_svn2git= + ;; + l) + run_local=1 + ;; + s) + do_gitsvn= + ;; + esac +done +shift $(($OPTIND - 1)) + case "$1" in base) ;; ports) ;; doc) ;; *) echo "Need to specify which repo to convert" >&2 exit 1 ;; esac TYPE=$1 LOCK="/tmp/gitconv_${TYPE}.lock" trap 'rm -f "${LOCK}" ; exit 1' 1 2 3 15 if ! shlock -p $$ -f "${LOCK}"; then echo >&2 echo "Locked by ${TYPE} (`cat "${LOCK}"`), running too long? Please fix ..." >&2 exit 1 fi svn2git() { local rules source target dest d rules=$1; shift source=$1; shift dest="$@" # FIXME: error prone, yuck target=${rules%.rules}.git target=`basename $target` test -d "$BASE" || { echo "$BASE is not a directory, exiting ..." >&2; exit 1; } test -f "$rules" || { echo "$rules do not exist, exiting ..." >&2; exit 1; } cd $BASE echo "Converting $source to $target using svn2git" $SVN2GIT --add-metadata-notes --identity-domain FreeBSD.org \ --rules $rules $source if [ $? != 0 ]; then echo "Error in svn2git conversion of $source" >&2 exit 1 fi touch $target/git-daemon-export-ok - if [ -z "$dest" ]; then + if [ -z "$dest" -o -n "$run_local" ]; then return fi echo "Pushing $target to $dest" cd $target && for d in $dest; do git push $d || { echo "Error in pushing to $dest" >&2; exit 1; } done } gitsvn() { local target dest d target=$1; shift dest="$@" test -d "$BASE/$target/.git" || { echo "$BASE/$target is not a git repo, exiting ..." >&2; exit 1; } cd $BASE/$target echo "Converting $target using git-svn" git svn rebase if [ $? != 0 ]; then echo "Error in git-svn conversion of $target" >&2 exit 1 fi - if [ -z "$dest" ]; then + if [ -z "$dest" -o -n "$run_local" ]; then return fi echo "Pushing $target to $dest" for d in $dest; do git push $d || { echo "Error in pushing to $dest" >&2; exit 1; } done } -case "$TYPE" in - base) - gitsvn src-head.git github - ;; - doc) - gitsvn doc-head.git github - ;; - ports) - gitsvn ports-head.git github - ;; -esac +if [ -n "$do_gitsvn" ]; then + case "$TYPE" in + base) gitsvn src-head.git github ;; + doc) gitsvn doc-head.git github ;; + ports) gitsvn ports-head.git github ;; + esac +fi -case "$TYPE" in - base) - svn2git $RULES_DIR/freebsd-base.rules ${SRC_REPO} github bitbucket #googlecode - ;; - doc) - svn2git $RULES_DIR/freebsd-doc.rules ${DOC_REPO} github - ;; - ports) - svn2git $RULES_DIR/freebsd-ports.rules ${PORTS_REPO} github - ;; -esac +if [ -n "$do_svn2git" ]; then + case "$TYPE" in + base) svn2git $RULES_DIR/freebsd-base.rules ${SRC_REPO} github bitbucket ;; + doc) svn2git $RULES_DIR/freebsd-doc.rules ${DOC_REPO} github ;; + ports) svn2git $RULES_DIR/freebsd-ports.rules ${PORTS_REPO} github ;; + esac +fi