<commit_before>#!/bin/bash -eu

configDir=$1

function processText() {
    while read line ; do
	processLine "$line"
    done
}

function processLine() {
    local line=$1
    if isActionableLine "$line" ; then
	processValidLine "$line"
    fi
}

# Ignore comments and empty lines
function isActionableLine() {
    local line=$1
    [[ $(cut -b 1 <(echo $line)) != '#' && \
	! -z "$line" ]]
}

function processValidLine() {
    local line=$1
    local cmdType=$(echo $line | cut -d ' ' -f 1)
    local cmdVal=$(echo $line | cut -d ' ' -f 2)
    local cmdQual=$(echo $line | cut -d ' ' -f 3)
    processFields $cmdType $cmdVal $cmdQual
}

function processFields() {
    local cmdType=$1; shift
    if [[ $cmdType == "import" ]] ; then
	importDirectory $@
    elif [[ $cmdType == "remote" ]] ; then
	importRemote $@
    fi
}

function importDirectory() {
    if [[ $# -gt 1 ]] ; then
	importQualified $@
    else
	importDirect $@
    fi
}

function importDirect() {
    local projectDir=$1
    includeProject $projectDir $importsDir
}

function importQualified() {
    local projectDir=$1
    local qualifiedSub=$2
    local qualifiedDir=$qualifiedSrc/$qualifiedSub
    mkdir -p $qualifiedDir
    includeProject $projectDir $qualifiedDir
}

function importRemote() {
    local projectUrl=$1; shift
    srcDir=$(retrieveRemote $projectUrl)
    echo "Done" >&2
    echo importDirectory $srcDir $@ >&2
    importDirectory $srcDir $@
}

cat $configDir | processText<commit_msg>Remove debug hooks<commit_after>#!/bin/bash -eu

configDir=$1

function processText() {
    while read line ; do
	processLine "$line"
    done
}

function processLine() {
    local line=$1
    if isActionableLine "$line" ; then
	processValidLine "$line"
    fi
}

# Ignore comments and empty lines
function isActionableLine() {
    local line=$1
    [[ $(cut -b 1 <(echo $line)) != '#' && \
	! -z "$line" ]]
}

function processValidLine() {
    local line=$1
    local cmdType=$(echo $line | cut -d ' ' -f 1)
    local cmdVal=$(echo $line | cut -d ' ' -f 2)
    local cmdQual=$(echo $line | cut -d ' ' -f 3)
    processFields $cmdType $cmdVal $cmdQual
}

function processFields() {
    local cmdType=$1; shift
    if [[ $cmdType == "import" ]] ; then
	importDirectory $@
    elif [[ $cmdType == "remote" ]] ; then
	importRemote $@
    fi
}

function importDirectory() {
    if [[ $# -gt 1 ]] ; then
	importQualified $@
    else
	importDirect $@
    fi
}

function importDirect() {
    local projectDir=$1
    includeProject $projectDir $importsDir
}

function importQualified() {
    local projectDir=$1
    local qualifiedSub=$2
    local qualifiedDir=$qualifiedSrc/$qualifiedSub
    mkdir -p $qualifiedDir
    includeProject $projectDir $qualifiedDir
}

function importRemote() {
    local projectUrl=$1; shift
    srcDir=$(retrieveRemote $projectUrl)
    importDirectory $srcDir $@
}

cat $configDir | processText
{'fraction_non_alphanumeric': 0.13474194665742986, 'fraction_numerical': 0.010391409767925183, 'mean_word_length': 3.2533136966126657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6165855', 'n_tokens_mistral': 963, 'n_tokens_neox': 927, 'n_words': 262}