From 7c7bb4dd48457c6e35e63cffce137e0f49dd59ff Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Thu, 14 Jun 2018 20:06:23 -0500 Subject: [PATCH] indent_common.sh: Add a REPORT_ONLY mode If REPORT_ONLY is set to true, indent and indent-branch only report errors without actually modifying any files. --- contrib/utilities/indent_common.sh | 40 ++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/contrib/utilities/indent_common.sh b/contrib/utilities/indent_common.sh index 0d1f209cea..99a8fbbbed 100644 --- a/contrib/utilities/indent_common.sh +++ b/contrib/utilities/indent_common.sh @@ -67,6 +67,29 @@ checks() { # export TMPDIR="${TMPDIR:-/tmp}" +# +# Depending on whether REPORT_ONLY is set to true, or false, either report +# an issue or print a status +# + +export REPORT_ONLY="${REPORT_ONLY:-false}" + +fix_or_report() +{ + file="${1}" + tmpfile="${2}" + message="${3}" + + if ! diff -q "${file}" "${tmpfile}" >/dev/null; then + if ${REPORT_ONLY}; then + echo " ${file} - ${message}" + else + mv "${tmpfile}" "${file}" + fi + fi +} +export -f fix_or_report + # # In order to format .cc and .h files we have to make sure that we override # the source/header file only if the actual contents changed. @@ -80,7 +103,7 @@ format_file() tmpfile="$(mktemp "${TMPDIR}/$(basename "$1").tmp.XXXXXXXX")" clang-format "${file}" > "${tmpfile}" - diff -q "${file}" "${tmpfile}" >/dev/null || mv "${tmpfile}" "${file}" + fix_or_report "${file}" "${tmpfile}" "file indented incorrectly" rm -f "${tmpfile}" } export -f format_file @@ -112,7 +135,7 @@ format_inst() sed -i -e 's#{ // namespace#\\{#g' "${tmpfile}new" sed -i -e 's#}[ ]*// namespace.*#\\}#g' "${tmpfile}new" - diff -q "${file}" "${tmpfile}new" >/dev/null || mv "${tmpfile}new" "${file}" + fix_or_report "${file}" "${tmpfile}new" "file indented incorrectly" rm -f "${tmpfile}" "${tmpfile}new" } export -f format_inst @@ -128,8 +151,9 @@ dos_to_unix() tmpfile="$(mktemp "${TMPDIR}/$(basename "$1").tmp.XXXXXXXX")" tr -d '\015' <"${file}" >"${tmpfile}" - diff -q "${file}" "${tmpfile}" >/dev/null || mv "${tmpfile}" "${file}" - rm -f "${tmpfile}" + + fix_or_report "${file}" "${tmpfile}" "file has non-unix line-ending '\\r\\n'" + rm -f "${tmpfile}" "${tmpfile}" } export -f dos_to_unix @@ -141,7 +165,13 @@ fix_permissions() { file="${1}" - chmod 644 "${file}" + if [ "$(stat -c '%a' ${file})" != "644" ]; then + if ${REPORT_ONLY}; then + echo " ${file} - file has incorrect permissions" + else + chmod 644 "${file}" + fi + fi } export -f fix_permissions -- 2.39.5