diff options
Diffstat (limited to 'helpers/llvm-common')
-rwxr-xr-x | helpers/llvm-common | 94 |
1 files changed, 87 insertions, 7 deletions
diff --git a/helpers/llvm-common b/helpers/llvm-common index 47b4937..33a9129 100755 --- a/helpers/llvm-common +++ b/helpers/llvm-common @@ -2,16 +2,17 @@ # The common script is only meant to be included from other LLVM helper scripts -if [[ $LLVM_SRC = '' ]]; then - echo "Please, define \$LLVM_SRC" - exit -1 -fi -if [[ $LLVM_BLD = '' ]]; then - echo "Please, define \$LLVM_BLD" +# Verify the compulsory environment variables - these must be set for all the +# helper scripts. +if [[ $LLVM_ROOT = '' ]]; then + echo "Please, define \$LLVM_ROOT to point to the root" + echo "path where the worktree setup should be performed" exit -1 fi + if [[ $LLVM_GITRW = '' ]]; then - echo "Please, define \$LLVM_GITRW" + echo "Please, define \$LLVM_GITRW to yes if you" + echo "want to set up Git-SVN and no otherwise" exit -1 fi if [[ $LLVM_GITUSER = '' ]]; then @@ -24,6 +25,36 @@ if [[ $LLVM_GITRW = 'yes' ]] && [[ $LLVM_SVNUSER = '' ]]; then exit 1 fi +# Verify the environment variables that should be set by llvm-env +verify_env() { + if [[ $LLVM_SRC = '' ]]; then + echo "Please, define \$LLVM_SRC to point to the current LLVM" + echo "worktree directory, or run llvm-env to set it for you" + exit -1 + fi + if [[ $LLVM_BLD = '' ]]; then + echo "Please, define \$LLVM_BLD to point to the current LLVM" + echo "build directory, or run llvm-env to set it for you" + exit -1 + fi +} + +has() { + if [[ $1 = '' || $2 = '' ]]; then + echo no + return + fi + local item=$1 + shift + for each in $*; do + if [[ $item = $each ]]; then + echo yes + return + fi + done + echo no +} + get_branch() { branch=`git rev-parse --abbrev-ref HEAD` if [[ $? != 0 ]]; then @@ -44,6 +75,13 @@ get_branches() { echo $branches } +has_branch() { + branch=$1 + branches=`get_branches` + result=`has $branch $branches` + echo $result +} + safe_run() { "$@" if [[ $? != 0 ]]; then @@ -59,3 +97,45 @@ is_git() { is_git_svn() { test -f `git rev-parse --show-toplevel`/.git/svn/.metadata } + +# Quiet pushd & popd +pushdq() { + pushd "$@" > /dev/null +} + +popdq() { + popd "$@" > /dev/null +} + +add_worktree() { + repo_dir=$1 + worktree_dir=$2 + branch=$3 + + pushdq $repo_dir + + if [ `get_branch` != 'master' ]; then + echo "$repo_dir isn't on master, bailing out" + exit 1 + fi + + if [ `has_branch $branch` = "yes" ]; then + safe_run git worktree add $worktree_dir $branch + else + safe_run git worktree add -b $branch $worktree_dir + fi + popdq +} + +remove_worktree() { + repo_dir=$1 + + if [ "$2" != "" ]; then + worktree_dir=$2 + safe_run rm -rf $worktree_dir + fi + + pushdq $repo_dir + safe_run git worktree prune + popdq +} |