From 1b537ca3787f3ef37898ac3dbba09ab7a089de03 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 12 Aug 2020 12:03:34 -0400 Subject: [PATCH] Avoid trailing whitespace check to modify timestamps unnecessarily --- contrib/utilities/indent_common.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 -- 2.39.5