Speed up pre-commit boilerplate by only checking changed files

Although the boilerplate checker was very fast it can be faster. With
this change we can hand the boilerplate a list of files which need to be
checked or give it no files. If given no files it will run all files in
the repo. Before you had to explicitly tell the boiler checker the
'extention' of the the files.  In this case we let the checker figure it
out and load the headers as needed.

Doing the whole repo takes about 0.4 seconds. Doing a single go file
takes < .04 seconds.
This commit is contained in:
Eric Paris
2015-05-09 12:21:10 -04:00
parent c367d3c2e5
commit 8a91d86783
3 changed files with 75 additions and 49 deletions

View File

@@ -39,11 +39,12 @@ fi
echo "${reset}"
echo -ne "Checking for files that need boilerplate... "
out=($(hack/verify-boilerplate.sh))
if [[ $? -ne 0 ]]; then
files=($(git diff --cached --name-only --diff-filter ACM))
out=($(hack/boilerplate/boilerplate.py "${files[@]}"))
if [[ "${#out}" -ne 0 ]]; then
echo "${red}ERROR!"
echo "Some files are missing the required boilerplate header"
echo "from hooks/boilerplate.txt:"
echo "from hack/boilerplate/boilerplate.*.txt:"
for f in "${out[@]}"; do
echo " ${f}"
done