]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid trailing whitespace check to modify timestamps unnecessarily 10825/head
authorDaniel Arndt <arndtd@ornl.gov>
Wed, 12 Aug 2020 16:03:34 +0000 (12:03 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Wed, 12 Aug 2020 16:04:05 +0000 (12:04 -0400)
contrib/utilities/indent_common.sh

index f2f98c39f7ffc51c8f4d86d911c23b3be77bfc12..9c7df35c88a90825a8701d0f9b1e1ceb3e48e36f 100644 (file)
@@ -163,16 +163,19 @@ format_file()
 export -f format_file
 
 #
-# Remove trailiing whitespace. Mac OSX requires an extension for a backup file
-# for in-place replacements. So we need to provide something before the regex.
-# Using '-e' avoids creating these files on GNU platforms at least.
-# For Mac OSX, we still need to delete the created file.
+# Remove trailing whitespace.
 #
 
 remove_trailing_whitespace()
 {
-  sed -i -e 's/\s\+$//g' "$1"
-  rm -f "$1-e"
+  file="${1}"
+  tmpfile="$(mktemp "${TMPDIR}/$(basename "$1").tmp.XXXXXXXX")"
+
+  sed 's/\s\+$//g' "${file}" > "${tmpfile}"
+  if ! diff -q "${file}" "${tmpfile}" >/dev/null; then
+    mv "${tmpfile}" "${file}"
+  fi
+  rm -f "${tmpfile}"
 }
 export -f remove_trailing_whitespace
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.