<commit_before>_hash_obj() {
    file="$1"
    echo $(shasum "${file}" | awk '{print $1}')
}

init() {
    path="$1";
    if [ ! -d "${path}" ]; then
        echo "Path '${path}' does not exist"; return;
    fi
    cd "${path}";
    export DVCSH="$(pwd)/.dvcsh"
    mkdir -p "${DVCSH}/objects";
    echo "Initialized empty repository in ${DVCSH}/";
}

add() {
    file="$1";
    sha=$(_hash_obj "${file}");
    cp -p "$1" "${DVCSH}/objects/${sha}"

    if [ -f "${DVCSH}/index" ]; then
        egrep -v "\t${file}\$" "${DVCSH}/index" >> "${DVCSH}/index.tmp"
    fi
    printf "${sha}\t${file}\n" >> "${DVCSH}/index.tmp"
    mv "${DVCSH}/index.tmp" "${DVCSH}/index"
}

commit() {
    sha=$(_hash_obj "${DVCSH}/index");
    if [ -f "${DVCSH}/objects/${sha}" ]; then
        echo "nothing to commit"; return;
    fi
    cp -p "${DVCSH}/index" "${DVCSH}/objects/${sha}"

    echo "index: ${sha}" > "${DVCSH}/commit.last";
    echo "date: $(date)" >> "${DVCSH}/commit.last";

    if [ -f "${DVCSH}/HEAD" ]; then
        echo "parent: $(cat "${DVCSH}/HEAD")" >> "${DVCSH}/commit.last";
    fi

    echo "comment: ${1:-(no comment)}" >> "${DVCSH}/commit.last"

    sha=$(_hash_obj "${DVCSH}/commit.last");
    cp -p "${DVCSH}/commit.last" "${DVCSH}/objects/${sha}"

    echo "${sha}" > "${DVCSH}/HEAD";
}

log() {
    if [ ! -f "${DVCSH}/HEAD" ]; then echo "No commits yet"; return; fi
    sha=$(cat "${DVCSH}/HEAD");
    path="${DVCSH}/objects/${sha}"

    while [ ! -z "${sha}" ]; do
        echo "commit: ${sha}"
        printf "  "; egrep '^date: ' ${path}
        printf "  "; egrep '^comment: ' ${path}
        echo

        sha=$(egrep -h '^parent: ' "${path}" | awk '{print $2}')
        path="${DVCSH}/objects/${sha}"
    done
}<commit_msg>- wrap some lines for slide<commit_after>_hash_obj() {
    file="$1"
    echo $(shasum "${file}" | awk '{print $1}')
}

init() {
    path="$1";
    if [ ! -d "${path}" ]; then
        echo "Path '${path}' does not exist"; return;
    fi
    cd "${path}";
    export DVCSH="$(pwd)/.dvcsh"
    mkdir -p "${DVCSH}/objects";
    echo "Initialized empty repository in ${DVCSH}/";
}

add() {
    file="$1";
    sha=$(_hash_obj "${file}");
    cp -p "$1" "${DVCSH}/objects/${sha}"

    if [ -f "${DVCSH}/index" ]; then
        egrep -v "\t${file}\$" "${DVCSH}/index" >> "${DVCSH}/index.tmp"
    fi
    printf "${sha}\t${file}\n" >> "${DVCSH}/index.tmp"
    mv "${DVCSH}/index.tmp" "${DVCSH}/index"
}

commit() {
    sha=$(_hash_obj "${DVCSH}/index");
    if [ -f "${DVCSH}/objects/${sha}" ]; then
        echo "nothing to commit"; return;
    fi
    cp -p "${DVCSH}/index" "${DVCSH}/objects/${sha}"

    echo "index: ${sha}" > "${DVCSH}/commit.last";
    echo "date: $(date)" >> "${DVCSH}/commit.last";

    if [ -f "${DVCSH}/HEAD" ]; then
        echo "parent: $(cat "${DVCSH}/HEAD")" >> "${DVCSH}/commit.last";
    fi

    echo "comment: ${1:-(no comment)}" >> "${DVCSH}/commit.last"

    sha=$(_hash_obj "${DVCSH}/commit.last");
    cp -p "${DVCSH}/commit.last" "${DVCSH}/objects/${sha}"

    echo "${sha}" > "${DVCSH}/HEAD";
}

log() {
    if [ ! -f "${DVCSH}/HEAD" ]; then
        echo "No commits yet"; return;
    fi
    sha=$(cat "${DVCSH}/HEAD");
    path="${DVCSH}/objects/${sha}"

    while [ ! -z "${sha}" ]; do
        echo "commit: ${sha}"
        printf "  "; egrep '^date: ' ${path}
        printf "  "; egrep '^comment: ' ${path}
        echo

        sha=$(egrep -h '^parent: ' "${path}" | awk '{print $2}')
        path="${DVCSH}/objects/${sha}"
    done
}
{'fraction_non_alphanumeric': 0.26467236467236466, 'fraction_numerical': 0.003988603988603989, 'mean_word_length': 2.6308169596690796, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '3879793', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1313, 'n_words': 299}