Bug 1384791 - Fix clang-format script, r?franziskus
try: -p none -t clang-format
--- 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 ]]