]> https://gitweb.dealii.org/ - dealii.git/commitdiff
indent_common.sh: Add a REPORT_ONLY mode
authorMatthias Maier <tamiko@43-1.org>
Fri, 15 Jun 2018 01:06:23 +0000 (20:06 -0500)
committerMatthias Maier <tamiko@43-1.org>
Sat, 16 Jun 2018 04:45:39 +0000 (23:45 -0500)
If REPORT_ONLY is set to true, indent and indent-branch only report
errors without actually modifying any files.

contrib/utilities/indent_common.sh

index 0d1f209ceadd34cee14808fc2cdf709ca386a408..99a8fbbbed22739b40be9c5328989a5bbc0c3f74 100644 (file)
@@ -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
 

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.