mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 13:43:47 +01:00
573ab70bfe
The format is the same as in my previous efforts here. The script is a little tricky, since it invokes both clang-format and codetool, and it makes sure that files do not have a changed mtime unless there is actually some change in the file.
35 lines
1.2 KiB
Bash
Executable File
35 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# Copyright 2020, The Tor Project, Inc.
|
|
# See LICENSE for licensing information.
|
|
|
|
# This script runs "clang-format" and "codetool" in sequence over each of
|
|
# our source files, and replaces the original file only if it has changed.
|
|
#
|
|
# We can't just use clang-format -i, since we also want to use codetool to
|
|
# reformat a few things back to how we want them, and we want avoid changing
|
|
# the mtime on files that didn't actually change.
|
|
|
|
set -e
|
|
|
|
cd "$(dirname "$0")/../../src/"
|
|
|
|
# Shellcheck complains that a for loop over find's output is unreliable,
|
|
# since there might be special characters in the output. But we happen
|
|
# to know that none of our C files have special characters or spaces in
|
|
# their names, so this is safe.
|
|
#
|
|
# shellcheck disable=SC2044
|
|
for fname in $(find lib core feature app test tools -name '[^.]*.[ch]'); do
|
|
tmpfname="${fname}.clang_fmt.tmp"
|
|
rm -f "${tmpfname}"
|
|
clang-format --style=file "${fname}" > "${tmpfname}"
|
|
../scripts/maint/codetool.py "${tmpfname}"
|
|
if cmp "${fname}" "${tmpfname}" >/dev/null 2>&1; then
|
|
echo "No change in ${fname}"
|
|
rm -f "${tmpfname}"
|
|
else
|
|
echo "Change in ${fname}"
|
|
mv "${tmpfname}" "${fname}"
|
|
fi
|
|
done
|