Skip to content

Commit

Permalink
script/validate-c: simplify, check everything
Browse files Browse the repository at this point in the history
Instead of using a complex logic to figure out which files were modified
and checking those, just check all files in the repo (not that we have
many). This serves two purposes:

1. Making sure the formatting is always checked (I suspect it was not
   working as it should).

2. Simplify the script logic (a lot).

While at it, do some other minor improvements:

 - actually show the diff to a user (and rely on diff exit code
   rather than output or the lack thereof);

 - don't create temp files -- use bash here-file instead.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Mar 16, 2021
1 parent 37577ec commit 9b8a0e0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 43 deletions.
33 changes: 0 additions & 33 deletions script/.validate

This file was deleted.

13 changes: 3 additions & 10 deletions script/validate-c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/bin/bash

source "$(dirname "$BASH_SOURCE")/.validate"

IFS=$'\n'
files=($(validate_diff --diff-filter=ACMR --name-only -- '*.c' | grep -v '^vendor/' || true))
files=($(git ls-files '*.c' | grep -v '^vendor/' || true))
unset IFS

# indent(1): "You must use the ‘-T’ option to tell indent the name of all the typenames in your program that are defined by typedef."
Expand All @@ -15,21 +13,16 @@ fi

badFiles=()
for f in "${files[@]}"; do
orig=$(mktemp)
formatted=$(mktemp)
# we use "git show" here to validate that what's committed is formatted
git show "$VALIDATE_HEAD:$f" >${orig}
${INDENT} ${orig} -o ${formatted}
if [ "$(diff -u ${orig} ${formatted})" ]; then
if ! diff -u "$f" <($INDENT -st $f); then
badFiles+=("$f")
fi
rm -f ${orig} ${formatted}
done

if [ ${#badFiles[@]} -eq 0 ]; then
echo 'Congratulations! All C source files are properly formatted.'
else
{
echo
echo "These files are not properly formatted:"
for f in "${badFiles[@]}"; do
echo " - $f"
Expand Down

0 comments on commit 9b8a0e0

Please sign in to comment.