<commit_before>#!/bin/bash -e
#
# Copyright (c) 2009-2012 <NAME> <<EMAIL>>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

DIR=$PWD

git_kernel_stable () {
	echo "fetching from stable kernel.org tree"
	git fetch ${linux_stable} master --tags || true
}

git_kernel_torvalds () {
	echo "pulling from torvalds kernel.org tree"
	git pull ${GIT_OPTS} ${torvalds_linux} master --tags || true
	git tag | grep v${KERNEL_TAG} &>/dev/null || git_kernel_stable
}

check_and_or_clone () {
	if [ ! "${LINUX_GIT}" ] ; then
		if [ -f "${HOME}/linux-src/.git/config" ] ; then
			echo "Warning: LINUX_GIT not defined in system.sh, using default location: ${HOME}/linux-src"
		else
			echo "Warning: LINUX_GIT not defined in system.sh, cloning torvalds git tree to default location: ${HOME}/linux-src"
			git clone ${torvalds_linux} ${HOME}/linux-src
		fi
		LINUX_GIT="${HOME}/linux-src"
	fi
}

git_kernel () {
	check_and_or_clone

	#In the past some users set LINUX_GIT = DIR, fix that...
	if [ -f "${LINUX_GIT}/version.sh" ] ; then
		unset LINUX_GIT
		check_and_or_clone
	fi

	if [ ! -f "${LINUX_GIT}/.git/config" ] ; then
		unset LINUX_GIT
		check_and_or_clone
	fi

	cd ${LINUX_GIT}/
	echo "Debug: LINUX_GIT setup..."
	pwd
	cat .git/config
	echo "Updating LINUX_GIT tree via: git fetch"
	git fetch || true
	cd -

	if [ ! -f ${DIR}/KERNEL/.git/config ] ; then
		rm -rf ${DIR}/KERNEL/ || true
		git clone --shared ${LINUX_GIT} ${DIR}/KERNEL
	fi

	cd ${DIR}/KERNEL/

	if [ "${RUN_BISECT}" ] ; then
		git bisect reset || true
	fi

	#So we are now going to assume the worst, and create a new master branch
	git am --abort || echo "git tree is clean..."
	git add .
	git commit --allow-empty -a -m 'empty cleanup commit'

	git checkout origin/master -b tmp-master<commit_msg>git: make more bullet proof<commit_after>#!/bin/bash -e
#
# Copyright (c) 2009-2012 <NAME> <<EMAIL>>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

DIR=$PWD

git_kernel_stable () {
	echo "fetching from stable kernel.org tree"
	git fetch ${linux_stable} master --tags || true
}

git_kernel_torvalds () {
	echo "pulling from torvalds kernel.org tree"
	git pull ${GIT_OPTS} ${torvalds_linux} master --tags || true
	git tag | grep v${KERNEL_TAG} &>/dev/null || git_kernel_stable
}

check_and_or_clone () {
	if [ ! "${LINUX_GIT}" ] ; then
		if [ -f "${HOME}/linux-src/.git/config" ] ; then
			echo "Warning: LINUX_GIT not defined in system.sh, using default location: ${HOME}/linux-src"
		else
			echo "Warning: LINUX_GIT not defined in system.sh, cloning torvalds git tree to default location: ${HOME}/linux-src"
			git clone ${torvalds_linux} ${HOME}/linux-src
		fi
		LINUX_GIT="${HOME}/linux-src"
	fi
}

git_kernel () {
	check_and_or_clone

	#In the past some users set LINUX_GIT = DIR, fix that...
	if [ -f "${LINUX_GIT}/version.sh" ] ; then
		unset LINUX_GIT
		echo "Warning: LINUX_GIT is set as DIR:"
		check_and_or_clone
	fi

	#is the git directory user writable?
	if [ ! -w "${LINUX_GIT}" ] ; then
		unset LINUX_GIT
		echo "Warning: LINUX_GIT is not writable:"
		check_and_or_clone
	fi

	#is it actually a git repo?
	if [ ! -f "${LINUX_GIT}/.git/config" ] ; then
		unset LINUX_GIT
		echo "Warning: LINUX_GIT is an invalid tree:"
		check_and_or_clone
	fi

	cd ${LINUX_GIT}/
	echo "Debug: LINUX_GIT setup..."
	pwd
	cat .git/config
	echo "Updating LINUX_GIT tree via: git fetch"
	git fetch || true
	cd -

	if [ ! -f "${DIR}/KERNEL/.git/config" ] ; then
		rm -rf ${DIR}/KERNEL/ || true
		git clone --shared ${LINUX_GIT} ${DIR}/KERNEL
	fi

	#Automaticly, just recover the git repo from a git crash
	if [ -f "${DIR}/KERNEL/.git/index.lock" ] ; then
		rm -rf ${DIR}/KERNEL/ || true
		git clone --shared ${LINUX_GIT} ${DIR}/KERNEL
	fi

	cd ${DIR}/KERNEL/

	if [ "${RUN_BISECT}" ] ; then
		git bisect reset || true
	fi

	#So we are now going to assume the worst, and create a new master branch
	git am --abort || echo "git tree is clean..."
	git add .
	git commit --allow-empty -a -m 'empty cleanup commit'

	git checkout origin/master -b tmp-master
{'fraction_non_alphanumeric': 0.10835964766494931, 'fraction_numerical': 0.002659132458035566, 'mean_word_length': 3.82598235765838, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '176939', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1928, 'n_words': 777}