<commit_before>#!/bin/bash

# autorevision.sh - a shell script to get git / hg revisions etc. into binary builds.
# To use pass a type and a path to the desired output file:
# ./autorevision.sh h some/path/to/autorevision.h
# Note: the script will run at the root level of the repository that it is in.

# Config
AFILETYPE="${1}"
TARGETFILE="${2}"


# Functions to extract data from different repo types.
# For git repos
function gitRepo {
	cd "$(git rev-parse --show-toplevel)"
	
	# Is the working copy clean?
	git diff --quiet HEAD &> /dev/null
	WC_MODIFIED="${?}"
	
	# Enumeration of changesets
	VCS_NUM="$(git rev-list --count HEAD)"
	if [ -z "${VCS_NUM}" ]; then
		echo "warning: Counting the number of revisions may be slower due to an outdated git version less than 1.7.2.3. If something breaks, please update it."
		VCS_NUM="$(git rev-list HEAD | wc -l)"
	fi
	
	# The full revision hash
	VCS_FULL_HASH="$(git rev-parse HEAD)"
	
	# The short hash
	VCS_SHORT_HASH="$(echo ${VCS_FULL_HASH} | cut -b 1-7)"
	
	# Current branch
	VCS_URI=`git rev-parse --symbolic-full-name --verify $(git name-rev --name-only --no-undefined HEAD)`
	
	# Current tag (or uri if there is no tag)
	VCS_TAG="$(git describe --exact-match --tags 2>/dev/null)"
	if [ -z "${VCS_TAG}" ]; then
		VCS_TAG="${VCS_URI}"
	fi
	
	# Date of the curent commit
	VCS_DATE="$(git log -1 --pretty=format:%ci)"
}

# For hg repos
function hgRepo {
	cd "$(hg root)"
	
	# Is the working copy clean?
	hg sum | grep -q 'commit: (clean)'
	WC_MODIFIED="${?}"
	
	# Enumeration of changesets
	VCS_NUM="$(hg id -n)"
	
	# The full revision hash
	VCS_FULL_HASH="$(hg log -r ${VCS_NUM} -l 1 --template '{node}\n')"
	
	# The short hash
	VCS_SHORT_HASH="$(hg id -i)"
	
	# Current bookmark (bookmarks are roughly equivalent to git's branches) or branch if no bookmark
	VCS_URI="$(hg id -B | cut -d ' ' -f 1)"
	# Fall back to the branch if there are no bookmarks
	if [ -z "${VCS_URI}" ]; then
		VCS_URI="$(hg id -b)"
	fi
	
	# Current tag (or uri if there is no tag)
	if [ "$(hg log -r ${VCS_NUM} -l 1 --template '{latesttagdistance}\n')" = "0" ]; then
		VCS_TAG="`hg id -t | sed -e 's:qtip::' -e 's:tip::' -e 's:qbase::' -e 's:qparent::' -e "s:$(hg --color never qtop 2>/dev/null)::" | cut -d ' ' -f 1`"
	else
		VCS_TAG="${VCS_URI}"
	fi
	
	# Date of the curent commit
	VCS_DATE="$(hg log -r ${VCS_NUM} -l 1 --template '{date|isodatesec}\n')"
}


# Functions to output data in different formats.
# For header output
function hOutput {
	cat > "${TARGETFILE}" << EOF
/* ${VCS_FULL_HASH} */
#ifndef AUTOREVISION_H
#define AUTOREVISION_H

#define VCS_NUM			${VCS_NUM}
#define VCS_DATE		${VCS_DATE}
#define VCS_URI			${VCS_URI}
#define VCS_TAG			${VCS_TAG}

#define VCS_FULL_HASH					${VCS_FULL_HASH}
#define VCS_SHORT_HASH					${VCS_SHORT_HASH}
<commit_msg>Fix some white space issues.<commit_after>#!/bin/bash

# autorevision.sh - a shell script to get git / hg revisions etc. into binary builds.
# To use pass a type and a path to the desired output file:
# ./autorevision.sh h some/path/to/autorevision.h
# Note: the script will run at the root level of the repository that it is in.

# Config
AFILETYPE="${1}"
TARGETFILE="${2}"


# Functions to extract data from different repo types.
# For git repos
function gitRepo {
	cd "$(git rev-parse --show-toplevel)"

	# Is the working copy clean?
	git diff --quiet HEAD &> /dev/null
	WC_MODIFIED="${?}"

	# Enumeration of changesets
	VCS_NUM="$(git rev-list --count HEAD)"
	if [ -z "${VCS_NUM}" ]; then
		echo "warning: Counting the number of revisions may be slower due to an outdated git version less than 1.7.2.3. If something breaks, please update it."
		VCS_NUM="$(git rev-list HEAD | wc -l)"
	fi

	# The full revision hash
	VCS_FULL_HASH="$(git rev-parse HEAD)"

	# The short hash
	VCS_SHORT_HASH="$(echo ${VCS_FULL_HASH} | cut -b 1-7)"

	# Current branch
	VCS_URI=`git rev-parse --symbolic-full-name --verify $(git name-rev --name-only --no-undefined HEAD)`

	# Current tag (or uri if there is no tag)
	VCS_TAG="$(git describe --exact-match --tags 2>/dev/null)"
	if [ -z "${VCS_TAG}" ]; then
		VCS_TAG="${VCS_URI}"
	fi

	# Date of the curent commit
	VCS_DATE="$(git log -1 --pretty=format:%ci)"
}

# For hg repos
function hgRepo {
	cd "$(hg root)"

	# Is the working copy clean?
	hg sum | grep -q 'commit: (clean)'
	WC_MODIFIED="${?}"

	# Enumeration of changesets
	VCS_NUM="$(hg id -n)"

	# The full revision hash
	VCS_FULL_HASH="$(hg log -r ${VCS_NUM} -l 1 --template '{node}\n')"

	# The short hash
	VCS_SHORT_HASH="$(hg id -i)"

	# Current bookmark (bookmarks are roughly equivalent to git's branches) or branch if no bookmark
	VCS_URI="$(hg id -B | cut -d ' ' -f 1)"
	# Fall back to the branch if there are no bookmarks
	if [ -z "${VCS_URI}" ]; then
		VCS_URI="$(hg id -b)"
	fi

	# Current tag (or uri if there is no tag)
	if [ "$(hg log -r ${VCS_NUM} -l 1 --template '{latesttagdistance}\n')" = "0" ]; then
		VCS_TAG="`hg id -t | sed -e 's:qtip::' -e 's:tip::' -e 's:qbase::' -e 's:qparent::' -e "s:$(hg --color never qtop 2>/dev/null)::" | cut -d ' ' -f 1`"
	else
		VCS_TAG="${VCS_URI}"
	fi

	# Date of the curent commit
	VCS_DATE="$(hg log -r ${VCS_NUM} -l 1 --template '{date|isodatesec}\n')"
}


# Functions to output data in different formats.
# For header output
function hOutput {
	cat > "${TARGETFILE}" << EOF
/* ${VCS_FULL_HASH} */
#ifndef AUTOREVISION_H
#define AUTOREVISION_H

#define VCS_NUM			${VCS_NUM}
#define VCS_DATE		${VCS_DATE}
#define VCS_URI			${VCS_URI}
#define VCS_TAG			${VCS_TAG}

#define VCS_FULL_HASH					${VCS_FULL_HASH}
#define VCS_SHORT_HASH					${VCS_SHORT_HASH}

{'fraction_non_alphanumeric': 0.1543000178794922, 'fraction_numerical': 0.0060790273556231, 'mean_word_length': 3.570261437908497, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3775709', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2096, 'n_words': 710}