From 5131c961300e8e253b0c2f6c7c38ec23f343bb27 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 17 Jun 2013 12:24:00 +0000 Subject: [PATCH] build: fix CRLF issues in user directories even if they're whitelisted, or git-svn users will get all sorts of weird conflicts. --- build/check-source.sh | 53 ++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/build/check-source.sh b/build/check-source.sh index 217faf6d..46eeaf3d 100755 --- a/build/check-source.sh +++ b/build/check-source.sh @@ -62,10 +62,10 @@ fi # Find out whether we need to care about CRLF case "$(uname 2>/dev/null)" in MINGW*) - check_crlf=false + can_check_crlf=false ;; *) - check_crlf=true + can_check_crlf=true ;; esac @@ -103,11 +103,14 @@ done total_errors=0 for file in $FILES; do + should_check_crlf=false + should_check_spaces=false case "$file" in # These files we know how to handle *.c|*.cpp|*.m|*.mm|*.h|*.hh|*.lolfx|*.lua|*.l|*.y|*.sh|*.py) - fix_method="all" + should_check_crlf=true + should_check_spaces=true ;; *) continue @@ -131,14 +134,14 @@ for file in $FILES; do people/touky/*|\ people/benlitz/*|\ people/sam/lua-*) - fix_method="crlf" + should_check_spaces=false ;; esac clean=true # Check for CR LF - if [ "$check_crlf" = true ]; then + if [ "$can_check_crlf" = true -a "$should_check_crlf" = true ]; then ncrlfs="$(od -tx1 "$file" | cut -b8- | tr ' ' '\n' | grep -c 0d || true)" total_crlfs="$(($total_crlfs + $ncrlfs))" if [ "$ncrlfs" -gt 0 ]; then @@ -153,28 +156,32 @@ for file in $FILES; do fi # Check for trailing spaces - nspaces="$($SED 's/.*[^ \t]//' "$file" | tr -cd '\t ' | wc -c)" - total_spaces="$(($total_spaces + $nspaces))" - if [ "$nspaces" -gt 0 -a "$fix_method" = "all" ]; then - clean=false - if [ "$fix" = true ]; then - $SED -i 's/[[:space:]][[:space:]]*$//g' "$file" - info "$file has $nspaces trailing spaces" - else - error "$file has $nspaces trailing spaces" + if [ "$should_check_spaces" = true ]; then + nspaces="$($SED 's/.*[^ \t]//' "$file" | tr -cd '\t ' | wc -c)" + total_spaces="$(($total_spaces + $nspaces))" + if [ "$nspaces" -gt 0 ]; then + clean=false + if [ "$fix" = true ]; then + $SED -i 's/[[:space:]][[:space:]]*$//g' "$file" + info "$file has $nspaces trailing spaces" + else + error "$file has $nspaces trailing spaces" + fi fi fi # Check for tabs - ntabs="$(tr -cd '\t' < "$file" | wc -c)" - total_tabs="$(($total_tabs + $ntabs))" - if [ "$ntabs" -gt 0 -a "$fix_method" = "all" ]; then - clean=false - if [ "$fix" = true ]; then - $SED -i 's/\t/ /g' "$file" - info "$file has $ntabs tabs" - else - error "$file has $ntabs tabs" + if [ "$should_check_spaces" = true ]; then + ntabs="$(tr -cd '\t' < "$file" | wc -c)" + total_tabs="$(($total_tabs + $ntabs))" + if [ "$ntabs" -gt 0 ]; then + clean=false + if [ "$fix" = true ]; then + $SED -i 's/\t/ /g' "$file" + info "$file has $ntabs tabs" + else + error "$file has $ntabs tabs" + fi fi fi