Bug 1384791 - Fix clang-format script, r?franziskus draft
authorMartin Thomson <martin.thomson@gmail.com>
Thu, 27 Jul 2017 12:04:59 +1000
changeset 15268 c82bdf18a45d1a06ab114464964fbd9bd5b6fdb3
parent 15265 9c94423e0669decabbb22b0d52ce31115c750265
push id2539
push usermartin.thomson@gmail.com
push dateThu, 27 Jul 2017 02:05:28 +0000
reviewersfranziskus
bugs1384791
Bug 1384791 - Fix clang-format script, r?franziskus try: -p none -t clang-format
automation/clang-format/run_clang_format.sh
--- a/automation/clang-format/run_clang_format.sh
+++ b/automation/clang-format/run_clang_format.sh
@@ -20,48 +20,49 @@ blacklist=(
      "./lib/libpkix" \
      "./lib/zlib" \
      "./lib/sqlite" \
      "./gtests/google_test" \
      "./.hg" \
      "./out" \
 )
 
-top="$(dirname $0)/../.."
-cd "$top"
+top=$(cd "$(dirname $0)/../.."; pwd -P)
 
 if [ $# -gt 0 ]; then
+    pushd . >/dev/null
     dirs=("$@")
 else
+    pushd "$top" >/dev/null
     dirs=($(find . -maxdepth 2 -mindepth 1 -type d ! -path . \( ! -regex '.*/' \)))
 fi
 
 format_folder()
 {
     for black in "${blacklist[@]}"; do
         if [[ "$1" == "$black"* ]]; then
             echo "skip $1"
             return 1
         fi
     done
     return 0
 }
 
 for dir in "${dirs[@]}"; do
-    if format_folder "$dir" ; then
+    if format_folder "$dir"; then
         c="${dir//[^\/]}"
         echo "formatting $dir ..."
-        depth=""
+	depth=()
         if [ "${#c}" == "1" ]; then
-            depth="-maxdepth 1"
+            depth+=(-maxdepth 1)
         fi
-        find "$dir" $depth -type f \( -name '*.[ch]' -o -name '*.cc' \) -exec clang-format -i {} \+
+        find "$dir" "${depth[@]}" -type f \( -name '*.[ch]' -o -name '*.cc' \) -exec clang-format -i {} \+
     fi
 done
 
 TMPFILE=$(mktemp /tmp/$(basename $0).XXXXXX)
 trap 'rm $TMPFILE' exit
-if (cd $(dirname $0); hg root >/dev/null 2>&1); then
+if [[ -d "$top/.hg" ]]; then
     hg diff --git "$top" | tee $TMPFILE
 else
     git -C "$top" diff | tee $TMPFILE
 fi
 [[ ! -s $TMPFILE ]]