From b7365ccace97eb212f304abc9cc416c5be18d96f Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Tue, 12 May 2015 16:11:04 -0400 Subject: [PATCH] Check if people copy, but do not update the boilerplate 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. --- hooks/boilerplate.go.txt | 2 +- hooks/boilerplate.py | 12 +++++++++--- hooks/boilerplate.py.txt | 2 +- hooks/boilerplate.sh.txt | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) mode change 100755 => 100644 hooks/boilerplate.py.txt diff --git a/hooks/boilerplate.go.txt b/hooks/boilerplate.go.txt index 837196def64..f3279e2bd0d 100644 --- a/hooks/boilerplate.go.txt +++ b/hooks/boilerplate.go.txt @@ -1,5 +1,5 @@ /* -Copyright 2014 The Kubernetes Authors All rights reserved. +Copyright YEAR The Kubernetes Authors All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/hooks/boilerplate.py b/hooks/boilerplate.py index 8414577e451..72497f5840b 100755 --- a/hooks/boilerplate.py +++ b/hooks/boilerplate.py @@ -47,11 +47,15 @@ def file_passes(filename, extension, ref, regexs): # trim our file to the same number of lines as the reference file data = data[:len(ref)] - # Replace all occurances of the regex "2015" with "2014" + p = regexs["year"] + for d in data: + if p.search(d): + return False + + # Replace all occurances of the regex "2015|2014" with "YEAR" p = regexs["date"] for i, d in enumerate(data): - - (data[i], found) = p.subn( '2014', d) + (data[i], found) = p.subn('YEAR', d) if found != 0: break @@ -81,6 +85,8 @@ def main(): ref = ref_file.read().splitlines() regexs = {} + # Search for "YEAR" which exists in the boilerplate, but shouldn't in the real thing + regexs["year"] = re.compile( 'YEAR' ) # dates can be 2014 or 2015, company holder names can be anything regexs["date"] = re.compile( '(2014|2015)' ) # strip // +build \n\n build constraints diff --git a/hooks/boilerplate.py.txt b/hooks/boilerplate.py.txt old mode 100755 new mode 100644 index abc2e0e2b35..2a413f07111 --- a/hooks/boilerplate.py.txt +++ b/hooks/boilerplate.py.txt @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright 2014 The Kubernetes Authors All rights reserved. +# Copyright YEAR The Kubernetes Authors All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/hooks/boilerplate.sh.txt b/hooks/boilerplate.sh.txt index 8b60d8dba5e..f592735e31e 100644 --- a/hooks/boilerplate.sh.txt +++ b/hooks/boilerplate.sh.txt @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2014 The Kubernetes Authors All rights reserved. +# Copyright YEAR The Kubernetes Authors All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.