From: Daniel Arndt Date: Wed, 12 Aug 2020 16:03:34 +0000 (-0400) Subject: Avoid trailing whitespace check to modify timestamps unnecessarily X-Git-Tag: v9.3.0-rc1~1187^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b537ca3787f3ef37898ac3dbba09ab7a089de03;p=dealii.git Avoid trailing whitespace check to modify timestamps unnecessarily --- diff --git a/contrib/utilities/indent_common.sh b/contrib/utilities/indent_common.sh index f2f98c39f7..9c7df35c88 100644 --- a/contrib/utilities/indent_common.sh +++ b/contrib/utilities/indent_common.sh @@ -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