<commit_before>#!/bin/bash

#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# ---------------------------------------
# versionOk checks version number against required version.
#   ``versionOk 1.2.3 2.0.4.7'' returns false value indicating
#       version you have is not at least version you need
#   if versionOk $haveversion $needversion; then
#      echo "Need at least version $needversion"; exit 1
#   fi
function versionOk() {
	local h=$1 n=$2
	# string compare -- no need to do more if the same
	[[ $h == $n ]] && return 0

	# split into fields
	local have=(${h//\./ })
	local need=(${n//\./ })
	# cmp first entry of each array.  Bail when unequal.
	while [[ -n $have && $have -eq $need ]]; do
		# pop 1st entry from each
		have=("${have[@]:1}")
		need=("${need[@]:1}")
	done
	if [[ ${have:-0} -lt ${need:-0} ]]; then
		return 1
	fi
	return 0
}

# ---------------------------------------
function getRevCount() {
	local buildNum=$(getBuildNumber)
	echo ${buildNum%.*}
}

# ---------------------------------------
function isInGitTree() {
	# ignore output -- use exit status
	git rev-parse --is-inside-work-tree >/dev/null 2>&1
}

# ---------------------------------------
function getBuildNumber() {
	local in_git=$()
	if isInGitTree; then
		local commits=$(git rev-list HEAD 2>/dev/null | wc -l)
		local sha=$(git rev-parse --short=8 HEAD)
		echo "$commits.$sha"
	else
		# Expect it's from the released tarball -- if BUILD_NUMBER file is not present,  abort
		if [[ ! -f $TC_DIR/BUILD_NUMBER ]]; then
			echo "Not in git repository and no BUILD_NUMBER present -- aborting!"
			exit 1
		fi
		grep -v '^#' $TC_DIR/BUILD_NUMBER
	fi
}

# ---------------------------------------
function getVersion() {
	local d="$1"
	local vf="$d/VERSION"
	[ -r $vf ] || { echo "Could not read $vf: $!"; exit 1; }
	cat "$vf"
}

# ---------------------------------------
function getRhelVersion {
        echo el$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
}
<commit_msg>if not in git tree, no tarball<commit_after>#!/bin/bash

#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# ---------------------------------------
# versionOk checks version number against required version.
#   ``versionOk 1.2.3 2.0.4.7'' returns false value indicating
#       version you have is not at least version you need
#   if versionOk $haveversion $needversion; then
#      echo "Need at least version $needversion"; exit 1
#   fi
function versionOk() {
	local h=$1 n=$2
	# string compare -- no need to do more if the same
	[[ $h == $n ]] && return 0

	# split into fields
	local have=(${h//\./ })
	local need=(${n//\./ })
	# cmp first entry of each array.  Bail when unequal.
	while [[ -n $have && $have -eq $need ]]; do
		# pop 1st entry from each
		have=("${have[@]:1}")
		need=("${need[@]:1}")
	done
	if [[ ${have:-0} -lt ${need:-0} ]]; then
		return 1
	fi
	return 0
}

# ---------------------------------------
function getRevCount() {
	local buildNum=$(getBuildNumber)
	echo ${buildNum%.*}
}

# ---------------------------------------
function isInGitTree() {
	# ignore output -- use exit status
	git rev-parse --is-inside-work-tree >/dev/null 2>&1
}

# ---------------------------------------
function getBuildNumber() {
	local in_git=$()
	if isInGitTree; then
		local commits=$(getRevCount)
		local sha=$(git rev-parse --short=8 HEAD)
		echo "$commits.$sha"
	else
		# Expect it's from the released tarball -- if BUILD_NUMBER file is not present,  abort
		if [[ ! -f $TC_DIR/BUILD_NUMBER ]]; then
			echo "Not in git repository and no BUILD_NUMBER present -- aborting!"
			exit 1
		fi
		grep -v '^#' $TC_DIR/BUILD_NUMBER
	fi
}

# ---------------------------------------
function getVersion() {
	local d="$1"
	local vf="$d/VERSION"
	[ -r $vf ] || { echo "Could not read $vf: $!"; exit 1; }
	cat "$vf"
}

# ---------------------------------------
function getRhelVersion {
        echo el$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
}

{'fraction_non_alphanumeric': 0.22107813446396124, 'fraction_numerical': 0.01150817686250757, 'mean_word_length': 2.304869913275517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '2925445', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1502, 'n_words': 559}