<commit_before>#!/bin/bash
RIOTBASE=$(git rev-parse --show-toplevel)
CURDIR=$(cd "$(dirname "$0")" && pwd)
UNCRUSTIFY_CFG="$RIOTBASE"/uncrustify-riot.cfg

WHITELIST=$CURDIR/whitelist.txt
BLACKLIST=$CURDIR/blacklist.txt

. "$RIOTBASE"/dist/tools/ci/changed_files.sh

# only consider whitelisted stuff, then filter out blacklist
# note: this also applies changed_files' default filter
FILES=$(changed_files | grep -xf "$WHITELIST" | grep -xvf "$BLACKLIST")

check () {
    for F in $FILES
    do
        OUT="$(uncrustify -c "$UNCRUSTIFY_CFG" -f "$RIOTBASE/$F" --check 2> /dev/null)"
        if [ "$OUT" ] ; then
            echo "Please run 'dist/tools/uncrustify/uncrustify.sh'"
            exit 1
        fi
    done
    echo "All files are uncrustified!"
}

exec_uncrustify () {
    if [ "$(git diff HEAD)" ] ; then
        echo "Please commit all changes before running uncrustify.sh"
        exit 1
    fi
    for F in $FILES
    do
        uncrustify -c "$UNCRUSTIFY_CFG" --no-backup "$RIOTBASE/$F"
    done
}

if [ "$1" == "--check" ] ; then
    check
else<commit_msg>dist/tools/uncrustify/uncrustify.sh: fix uncrustify check logic<commit_after>#!/bin/bash
RIOTBASE=$(git rev-parse --show-toplevel)
CURDIR=$(cd "$(dirname "$0")" && pwd)
UNCRUSTIFY_CFG="$RIOTBASE"/uncrustify-riot.cfg

WHITELIST=$CURDIR/whitelist.txt
BLACKLIST=$CURDIR/blacklist.txt

. "$RIOTBASE"/dist/tools/ci/changed_files.sh

# only consider whitelisted stuff, then filter out blacklist
# note: this also applies changed_files' default filter
FILES=$(changed_files | grep -xf "$WHITELIST" | grep -xvf "$BLACKLIST")

check () {
    for F in $FILES
    do
        uncrustify -c "$UNCRUSTIFY_CFG" -f "$RIOTBASE/$F" \
            --check > /dev/null 2>&1 || {
            echo "file $F needs to be uncrustified."
            echo "Please run 'dist/tools/uncrustify/uncrustify.sh'"
            exit 1
        }
    done
    echo "All files are uncrustified!"
}

exec_uncrustify () {
    if [ "$(git diff HEAD)" ] ; then
        echo "Please commit all changes before running uncrustify.sh"
        exit 1
    fi
    for F in $FILES
    do
        uncrustify -c "$UNCRUSTIFY_CFG" --no-backup "$RIOTBASE/$F"
    done
}

if [ "$1" == "--check" ] ; then
    check
else
{'fraction_non_alphanumeric': 0.14049217002237135, 'fraction_numerical': 0.004921700223713647, 'mean_word_length': 2.8156996587030716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '505452', 'n_tokens_mistral': 823, 'n_tokens_neox': 783, 'n_words': 202}