]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/tools/whitespace.sh
Merge branch 'terencehill/minplayers_per_team' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / tools / whitespace.sh
1 #!/usr/bin/env bash
2 set -eu
3 cd ${0%/*}
4 cd ..
5
6 function hash() {
7     git hash-object $1
8 }
9
10 function check() {
11     declare -l base="${1}"
12     # strip trailing spaces
13     STRIP_TRAILING_WS='s/[[:space:]]\+$//'
14     # line feed at EOF for #include to work properly
15     ENSURE_EOFLF='$a\'
16     find "$base" -type f -print0 | sort -z | while read -r -d '' file; do
17         oldHash=$(hash ${file})
18         oldTime=$(stat -c "%Y" ${file})
19         sed -i -e ${STRIP_TRAILING_WS} -e ${ENSURE_EOFLF} ${file}
20         newHash=$(hash ${file})
21         if [[ $newHash == $oldHash ]]; then touch -d @$oldTime ${file}; fi
22     done
23 }
24
25 check lib
26 check common
27 check ecs
28 check client
29 check server
30 check menu