X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Ftools%2Fwhitespace.sh;h=46db124008e83a88f998cd23897a2999c9761f20;hp=5662337411f3767e852ec0a8b65226cc64826ca6;hb=HEAD;hpb=f72821fdcebe3ca01181a99727a06198de65ea08 diff --git a/qcsrc/tools/whitespace.sh b/qcsrc/tools/whitespace.sh index 566233741..46db12400 100755 --- a/qcsrc/tools/whitespace.sh +++ b/qcsrc/tools/whitespace.sh @@ -1,19 +1,30 @@ -#!/bin/bash +#!/usr/bin/env bash set -eu -cd "$(dirname "$0")" +cd ${0%/*} cd .. +function hash() { + git hash-object $1 +} + function check() { declare -l base="${1}" - find "$base" -type f -print0 | sort -z | xargs -0 sed -i \ - `# strip trailing spaces` \ - -e 's/[[:space:]]*$//' \ - `# line feed at EOF for #include to work properly` \ - -e '$a\' + # strip trailing spaces + STRIP_TRAILING_WS='s/[[:space:]]\+$//' + # line feed at EOF for #include to work properly + ENSURE_EOFLF='$a\' + find "$base" -type f -print0 | sort -z | while read -r -d '' file; do + oldHash=$(hash ${file}) + oldTime=$(stat -c "%Y" ${file}) + sed -i -e ${STRIP_TRAILING_WS} -e ${ENSURE_EOFLF} ${file} + newHash=$(hash ${file}) + if [[ $newHash == $oldHash ]]; then touch -d @$oldTime ${file}; fi + done } check lib check common +check ecs check client check server check menu