<commit_before>
# This script is a part of Shore
# MIT License
# Copyright (c) 2016 <NAME>


function format_output() {

  CODE_IN="\e[49m"
  CODE_OUT="\033[1m\033[0m"

  case "$2" in
    hook)
      CODE_IN="\e[44m"
        ;;

    error)
      CODE_IN="\e[41m"
        ;;

    warning)
      CODE_IN="\e[93m"
        ;;

    success)
      CODE_IN="\e[92m"
        ;;
  esac

  printf "\033[1m${CODE_IN}$1${CODE_OUT}$3"

}



function include_files(){

    . "$(dirname "$0")/../../settings.sh"

    for F in "$(dirname "$0")"/../../runtime/*.sh; do
       . $F
    done
}


array_contains () { 
    local ARRAY="$1[@]"
    local SEEKING=$2
    local IN=1
    for ELEMENT in "${!ARRAY}"; do
        if [[ $ELEMENT == $SEEKING ]]; then
            IN=0
            break
        fi
    done
    return $IN
}


function run_hook() {

    HOOK_NAME="$1"
    ORIGIN_HOST_DIR_PATH="$2"
    shift 2

    CONTAINER_PROJECT_DIR_PATH="/home/$CONF_PROJECT_NAME"

    # Remap host path to container path
    ORIGIN_CONTAINER_DIR_PATH=${ORIGIN_HOST_DIR_PATH/$RT_HOST_SHARED_DIR_PATH/$CONTAINER_PROJECT_DIR_PATH}

    # List enabled bundles
    ENABLED_BUNDLES=()
    ENABLED_BUNDLES_LIST_FILE=$(readlink -f "$(dirname "$0")/../../profiles/$RT_PROFILE/bundles")
    while read BUNDLE || [[ -n "$BUNDLE" ]]; do

        # Trim
        if [[ "$BUNDLE" =~ ^[[:space:]]*([^[:space:]].*[^[:space:]])[[:space:]]*$ ]]; then 
            BUNDLE=${BASH_REMATCH[1]}
        fi

        # Add bundle to ENABLED_BUNDLES array if bundle name match
        if [[ $BUNDLE =~ ^([0-9a-z_]+)$ ]]; then
            ENABLED_BUNDLES+=("$BUNDLE")
        elif [[ $BUNDLE != \#* ]] && [ ! -z "$BUNDLE" ] ; then
            echo ""; format_output " > MISMATCH : \"$BUNDLE\" in \"$ENABLED_BUNDLES_LIST_FILE\" " "error" "\n"
        fi
    done <"$ENABLED_BUNDLES_LIST_FILE"


    # Loop on script list for the given hook
    HOOK_SCRIPT_LIST_FILE=$(readlink -f "$(dirname "$0")/../../profiles/$RT_PROFILE/on_$HOOK_NAME.hook")
    while read HOOK_SCRIPT || [[ -n "$HOOK_SCRIPT" ]]; do
        
        # Trim
        if [[ "$HOOK_SCRIPT" =~ ^[[:space:]]*([^[:space:]].*[^[:space:]])[[:space:]]*$ ]]; then 
            HOOK_SCRIPT=${BASH_REMATCH[1]}
        fi

        # Test if $HOOK_SCRIPT match the regexp
        if [[ $HOOK_SCRIPT =~ ^([0-9a-z_]+)\.([0-9a-z_]*)$ ]]; then

            HOOK_BUNDLE=${BASH_REMATCH[1]}<commit_msg>remove unnecessary readlink -f unsupported by macOS<commit_after>
# This script is a part of Shore
# MIT License
# Copyright (c) 2016 <NAME>


function format_output() {

  CODE_IN="\e[49m"
  CODE_OUT="\033[1m\033[0m"

  case "$2" in
    hook)
      CODE_IN="\e[44m"
        ;;

    error)
      CODE_IN="\e[41m"
        ;;

    warning)
      CODE_IN="\e[93m"
        ;;

    success)
      CODE_IN="\e[92m"
        ;;
  esac

  printf "\033[1m${CODE_IN}$1${CODE_OUT}$3"

}



function include_files(){

    . "$(dirname "$0")/../../settings.sh"

    for F in "$(dirname "$0")"/../../runtime/*.sh; do
       . $F
    done
}


array_contains () { 
    local ARRAY="$1[@]"
    local SEEKING=$2
    local IN=1
    for ELEMENT in "${!ARRAY}"; do
        if [[ $ELEMENT == $SEEKING ]]; then
            IN=0
            break
        fi
    done
    return $IN
}


function run_hook() {

    HOOK_NAME="$1"
    ORIGIN_HOST_DIR_PATH="$2"
    shift 2

    CONTAINER_PROJECT_DIR_PATH="/home/$CONF_PROJECT_NAME"

    # Remap host path to container path
    ORIGIN_CONTAINER_DIR_PATH=${ORIGIN_HOST_DIR_PATH/$RT_HOST_SHARED_DIR_PATH/$CONTAINER_PROJECT_DIR_PATH}

    # List enabled bundles
    ENABLED_BUNDLES=()
    ENABLED_BUNDLES_LIST_FILE=$(realpath "$(dirname "$0")/../../profiles/$RT_PROFILE/bundles")
    while read BUNDLE || [[ -n "$BUNDLE" ]]; do

        # Trim
        if [[ "$BUNDLE" =~ ^[[:space:]]*([^[:space:]].*[^[:space:]])[[:space:]]*$ ]]; then 
            BUNDLE=${BASH_REMATCH[1]}
        fi

        # Add bundle to ENABLED_BUNDLES array if bundle name match
        if [[ $BUNDLE =~ ^([0-9a-z_]+)$ ]]; then
            ENABLED_BUNDLES+=("$BUNDLE")
        elif [[ $BUNDLE != \#* ]] && [ ! -z "$BUNDLE" ] ; then
            echo ""; format_output " > MISMATCH : \"$BUNDLE\" in \"$ENABLED_BUNDLES_LIST_FILE\" " "error" "\n"
        fi
    done <"$ENABLED_BUNDLES_LIST_FILE"


    # Loop on script list for the given hook
    HOOK_SCRIPT_LIST_FILE=$(realpath "$(dirname "$0")/../../profiles/$RT_PROFILE/on_$HOOK_NAME.hook")
    while read HOOK_SCRIPT || [[ -n "$HOOK_SCRIPT" ]]; do
        
        # Trim
        if [[ "$HOOK_SCRIPT" =~ ^[[:space:]]*([^[:space:]].*[^[:space:]])[[:space:]]*$ ]]; then 
            HOOK_SCRIPT=${BASH_REMATCH[1]}
        fi

        # Test if $HOOK_SCRIPT match the regexp
        if [[ $HOOK_SCRIPT =~ ^([0-9a-z_]+)\.([0-9a-z_]*)$ ]]; then

            HOOK_BUNDLE=${BASH_REMATCH[1]}
{'fraction_non_alphanumeric': 0.1885109912899212, 'fraction_numerical': 0.020323517212774783, 'mean_word_length': 2.377450980392157, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4653146', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1845, 'n_words': 337}