<commit_before>#!/bin/bash
set -e

DB=pal.db

usage() {
    echo Usage: $0 PLATFORM >/dev/stderr
    echo >/dev/stderr
    echo Reports symbol size for all compilation units in a directory. >/dev/stderr
    exit 1
}

[ $# == 1 ] || usage
platform=$1

git_dirty() {
    # ??? TODO: Won't work if something was added to index ?
    [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]
}

already_built() {
    platform=$1
    sha=$2

    in_db=$(echo "select \"yes\" from report where platform=\"${platform}\" and commit_sha=\"${sha}\" LIMIT 1;" | sqlite3 ${DB})

    [ "x${in_db}" = "xyes" ]
}

if git_dirty; then
    echo Git index is dirty. Please stash your changes first. >&2
    exit 1
fi

if ! which sqlite3 >/dev/null; then
    echo This tool needs sqlite3 >&2
    exit 1
fi

if ! which gawk >/dev/null; then
    echo This tool needs gawk >&2
    exit 1
fi

top_srcdir=$(git rev-parse --show-toplevel)
cd $top_srcdir

# Copy tools outside of
toolsdir=$(mktemp -d)
cp -rf tools/* $toolsdir/

# Create Database if necessary
$toolsdir/regression/create-db.sh

# All commits on current branch (only follow first parent)
all=$(git log --oneline HEAD --first-parent --format="%H" --reverse)
logfile=$(mktemp)

# Keep track of original branch
orig_branch=$(git symbolic-ref --short HEAD 2>/dev/null)

# Create temporary branch
tmp_branch=regression-test-$(mktemp -u XXXX)
git checkout -b $tmp_branch >/dev/stderr

echo logfile=${logfile}
echo toolsdir=${toolsdir}
for c in $all; do
    git reset --hard $c
    [ -e src -a -e configure.ac ] || continue
    already_built $platform $c && continue
    echo "Building $c" >/dev/stderr
    if $toolsdir/regression/log-code-size.sh $platform > $logfile; then
        # TODO: Perform insert as transaction
        (echo ".mode csv" && echo ".import $logfile report") | sqlite3 ${DB}
    else
        echo Building $c failed
    fi
done

git checkout $orig_branch
git branch -d $tmp_branch
rm -rf $toolsdir
rm -rf $one
<commit_msg>tests:regression: Fix all.sh variable name change<commit_after>#!/bin/bash
set -e

DB=pal.db

usage() {
    echo Usage: $0 PLATFORM >/dev/stderr
    echo >/dev/stderr
    echo Reports symbol size for all compilation units in a directory. >/dev/stderr
    exit 1
}

[ $# == 1 ] || usage
platform=$1

git_dirty() {
    # ??? TODO: Won't work if something was added to index ?
    [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]
}

already_built() {
    platform=$1
    sha=$2

    in_db=$(echo "select \"yes\" from report where platform=\"${platform}\" and commit_sha=\"${sha}\" LIMIT 1;" | sqlite3 ${DB})

    [ "x${in_db}" = "xyes" ]
}

if git_dirty; then
    echo Git index is dirty. Please stash your changes first. >&2
    exit 1
fi

if ! which sqlite3 >/dev/null; then
    echo This tool needs sqlite3 >&2
    exit 1
fi

if ! which gawk >/dev/null; then
    echo This tool needs gawk >&2
    exit 1
fi

top_srcdir=$(git rev-parse --show-toplevel)
cd $top_srcdir

# Copy tools outside of
toolsdir=$(mktemp -d)
cp -rf tools/* $toolsdir/

# Create Database if necessary
$toolsdir/regression/create-db.sh

# All commits on current branch (only follow first parent)
all=$(git log --oneline HEAD --first-parent --format="%H" --reverse)
logfile=$(mktemp)

# Keep track of original branch
orig_branch=$(git symbolic-ref --short HEAD 2>/dev/null)

# Create temporary branch
tmp_branch=regression-test-$(mktemp -u XXXX)
git checkout -b $tmp_branch >/dev/stderr

echo logfile=${logfile}
echo toolsdir=${toolsdir}
for c in $all; do
    git reset --hard $c
    [ -e src -a -e configure.ac ] || continue
    already_built $platform $c && continue
    echo "Building $c" >/dev/stderr
    if $toolsdir/regression/log-code-size.sh $platform > $logfile; then
        # TODO: Perform insert as transaction
        (echo ".mode csv" && echo ".import $logfile report") | sqlite3 ${DB}
    else
        echo Building $c failed
    fi
done

git checkout $orig_branch
git branch -d $tmp_branch
rm -rf $toolsdir
rm -rf $logfile

{'fraction_non_alphanumeric': 0.13731865932966483, 'fraction_numerical': 0.010005002501250625, 'mean_word_length': 3.1099691675231242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '1272836', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1348, 'n_words': 471}