We found in that someone just copied/pasted the boilerplate language into
their code. But the boilerplate contains 2014, not 2015. We have 2 ways
to fix this.
1) Update the boilerplate to 2015 so people would get the right one.
2) Update the boilerplate so it doesn't make sense and then warn when
people use it.
This PR takes the second option. While options #1 seems easier, it will
get wrong in 2016, 17, 18 and it's unlikely anyone remember why they
need to update the boilerplate text and the regex rewrite. So just
make the humans do a tiny bit more work now.
Clayton pointed out that if he created a file with no /* in it anywhere
the boilerplate logic would crash like:
$ hack/verify-boilerplate.sh
Traceback (most recent call last):
File "hack/../hooks/boilerplate.py", line 87, in <module>
sys.exit(main())
File "hack/../hooks/boilerplate.py", line 83, in main
if not file_passes(filename, extention, ref, p):
File "hack/../hooks/boilerplate.py", line 38, in file_passes
while data[0] != "/*\n":
IndexError: list index out of range
That is because we were just stripping everything before the first line
that contained exacly "/*". If no such line existed it got to the end
and just kept going.
This does something smarter. We use a regex to look for one or more
lines which start // +build followed by a single newline and remove only
those. This obviously found one place where the package name was above
the license and was being missed by both the old and the new checker.
It also fixed the python spew and just tells you your file fails.
It's just a little bit faster.....
BEFORE:
$ time hack/verify-boilerplate.sh
real 0m9.378s
user 0m3.405s
sys 0m13.906s
AFTER:
$ time hack/verify-boilerplate.sh
real 0m0.181s
user 0m0.114s
sys 0m0.068s
Make the pre-commit check spit out cut-and-paste commands and be more
obvious about errors. Tested by making an invalid change and observing the
message generated.