]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/tools/whitespace.sh
Optimize vehicle impact code by only calling vlen() if damage would be taken
[xonotic/xonotic-data.pk3dir.git] / qcsrc / tools / whitespace.sh
index 5662337411f3767e852ec0a8b65226cc64826ca6..46db124008e83a88f998cd23897a2999c9761f20 100755 (executable)
@@ -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