Browse Source

build: fix CRLF issues in user directories even if they're whitelisted, or git-svn

users will get all sorts of weird conflicts.
legacy
Sam Hocevar sam 11 years ago
parent
commit
5131c96130
1 changed files with 30 additions and 23 deletions
  1. +30
    -23
      build/check-source.sh

+ 30
- 23
build/check-source.sh View File

@@ -62,10 +62,10 @@ fi
# Find out whether we need to care about CRLF # Find out whether we need to care about CRLF
case "$(uname 2>/dev/null)" in case "$(uname 2>/dev/null)" in
MINGW*) MINGW*)
check_crlf=false
can_check_crlf=false
;; ;;
*) *)
check_crlf=true
can_check_crlf=true
;; ;;
esac esac


@@ -103,11 +103,14 @@ done


total_errors=0 total_errors=0
for file in $FILES; do for file in $FILES; do
should_check_crlf=false
should_check_spaces=false


case "$file" in case "$file" in
# These files we know how to handle # These files we know how to handle
*.c|*.cpp|*.m|*.mm|*.h|*.hh|*.lolfx|*.lua|*.l|*.y|*.sh|*.py) *.c|*.cpp|*.m|*.mm|*.h|*.hh|*.lolfx|*.lua|*.l|*.y|*.sh|*.py)
fix_method="all"
should_check_crlf=true
should_check_spaces=true
;; ;;
*) *)
continue continue
@@ -131,14 +134,14 @@ for file in $FILES; do
people/touky/*|\ people/touky/*|\
people/benlitz/*|\ people/benlitz/*|\
people/sam/lua-*) people/sam/lua-*)
fix_method="crlf"
should_check_spaces=false
;; ;;
esac esac


clean=true clean=true


# Check for CR LF # 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)" ncrlfs="$(od -tx1 "$file" | cut -b8- | tr ' ' '\n' | grep -c 0d || true)"
total_crlfs="$(($total_crlfs + $ncrlfs))" total_crlfs="$(($total_crlfs + $ncrlfs))"
if [ "$ncrlfs" -gt 0 ]; then if [ "$ncrlfs" -gt 0 ]; then
@@ -153,28 +156,32 @@ for file in $FILES; do
fi fi


# Check for trailing spaces # 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
fi fi


# Check for tabs # 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
fi fi




Loading…
Cancel
Save