Commit cb640806 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Reduce forking in git-supertree

Gets rid of unnecessary forking of various commands from subshells,
preferring to exec from the subshell. Also removes one unnecessary
subshell fork entirely.
parent 43123012
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -202,15 +202,15 @@ new_worktree()

	if [[ "$BRANCH" = $(git symbolic-ref HEAD) ]]; then
		echo "ref: $BRANCH" > "$WT_REPO/HEAD"
		(cd "$WORKTREE"; git reset --hard)
		(cd "$WORKTREE"; exec git reset --hard)
	elif branch_exists "$BRANCH"; then
		(cd "$WORKTREE"; git checkout $(git for-each-ref "$BRANCH" --format='%(refname:short)') )
		(cd "$WORKTREE"; exec git checkout $(git for-each-ref "$BRANCH" --format='%(refname:short)') )
	elif [[ -n "$FROM" ]]; then
		(cd "$WORKTREE"; git checkout -b "$BRANCH" "$FROM")
		(cd "$WORKTREE"; exec git checkout -b "$BRANCH" "$FROM")
	elif [[ ${#BRANCH_REMOTES[*]} -eq 1 ]]; then
		(cd "$WORKTREE"; git checkout -b "$BRANCH" "$BRANCH_REMOTES")
		(cd "$WORKTREE"; exec git checkout -b "$BRANCH" "$BRANCH_REMOTES")
	elif branch_exists "${HEAD:=$(git symbolic-ref HEAD)}"; then
		(cd "$WORKTREE"; git checkout -b "$BRANCH" "$HEAD")
		(cd "$WORKTREE"; exec git checkout -b "$BRANCH" "$HEAD")
	else
		echo "ref: $BRANCH" > "$WT_REPO/HEAD"
	fi
@@ -271,12 +271,11 @@ action_clone()

	new_repo "${REPOPATH}"

	(
		cd ${REPOPATH}
	pushd >/dev/null ${REPOPATH}
	git remote add origin "${URL}"
	git fetch origin
	action_add "${BRANCH_NAME}:${BRANCH_PATH}" --from origin/${BRANCH_NAME}
	)
	popd >/dev/null

	set_head "${REPOPATH}" "${BRANCH_NAME}"
}
@@ -397,7 +396,7 @@ action_rm()
		rm -r "$BRANCH"
		(
			cd $(git rev-parse --git-common-dir)
			git worktree prune
			exec git worktree prune
		)
	else
		arg_error "The first argument must be a worktree name"