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

Disable parallel git jobs during update if Git < 2.8

parent 5abe0cf6
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -63,6 +63,22 @@ get_shell()
	echo sh
}

git_check()
{
	local v
	GIT_VERSION=0
	for v in `git --version|cut -f -d\ |tr '.' ' '`; do
		let 'GIT_VERSION = (GIT_VERSION << 8) + (v & 0xff)'
	done

	if [ $GIT_VERSION -gt 0x020800 ]; then
		local numcpu=`lscpu -p|grep '^[^#]'|wc -l`
		GIT_JOBS="--jobs $(((numcpu>1)?(numcpu-1):(numcpu)))"
	else
		GIT_JOBS=
	fi
}

update_worktree()
{
	local upstream=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`
@@ -72,7 +88,7 @@ update_worktree()
	local original=`git rev-parse HEAD`
	if git merge --ff --no-edit $upstream origin/master; then
		git submodule sync --recursive
		git submodule update --init --recursive
		git submodule update --init --recursive ${GIT_JOBS}
	else
		git reset $original
	fi
@@ -86,11 +102,8 @@ update_repos()
	git worktree add -f $worktree --detach origin/master
	cd $worktree

	local numcpu=`lscpu -p|grep '^[^#]'|wc -l`

	git submodule sync --recursive
	git submodule update --init --recursive \
		-j $(((numcpu>1)?(numcpu-1):(numcpu)))
	git submodule update --init --recursive ${GIT_JOBS}

	git submodule foreach --recursive '
		setting="submodule.${name}.auto-update";
@@ -148,6 +161,7 @@ do_update()

	(cd ~
		set -eu
		git_check &&
		update_repos &&
		update_worktree
	) || return