aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/distrib/check_copyright.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/distrib/check_copyright.py')
-rwxr-xr-xtools/distrib/check_copyright.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/tools/distrib/check_copyright.py b/tools/distrib/check_copyright.py
index a7efdc85cc..99771f9632 100755
--- a/tools/distrib/check_copyright.py
+++ b/tools/distrib/check_copyright.py
@@ -57,6 +57,9 @@ argp.add_argument('-a', '--ancient',
argp.add_argument('-f', '--fix',
default=False,
action='store_true');
+argp.add_argument('--precommit',
+ default=False,
+ action='store_true')
args = argp.parse_args()
# open the license text
@@ -68,9 +71,9 @@ with open('LICENSE') as f:
# that given a line of license text, returns what should
# be in the file
LICENSE_PREFIX = {
- '.c': r'\s*\*\s*',
- '.cc': r'\s*\*\s*',
- '.h': r'\s*\*\s*',
+ '.c': r'\s*(?://|\*)\s*',
+ '.cc': r'\s*(?://|\*)\s*',
+ '.h': r'\s*(?://|\*)\s*',
'.m': r'\s*\*\s*',
'.php': r'\s*\*\s*',
'.js': r'\s*\*\s*',
@@ -101,6 +104,10 @@ RE_LICENSE = dict(
for line in LICENSE))
for k, v in LICENSE_PREFIX.iteritems())
+if args.precommit:
+ FILE_LIST_COMMAND = 'git diff --name-only HEAD | grep -v ^third_party/'
+else:
+ FILE_LIST_COMMAND = 'git ls-tree -r --name-only -r HEAD | grep -v ^third_party/'
def load(name):
with open(name) as f:
@@ -124,8 +131,14 @@ def log(cond, why, filename):
# scan files, validate the text
ok = True
-for filename in subprocess.check_output('git ls-tree -r --name-only -r HEAD | grep -v ^third_party/',
- shell=True).splitlines():
+filename_list = []
+try:
+ filename_list = subprocess.check_output(FILE_LIST_COMMAND,
+ shell=True).splitlines()
+except subprocess.CalledProcessError:
+ sys.exit(0)
+
+for filename in filename_list:
if filename in KNOWN_BAD: continue
ext = os.path.splitext(filename)[1]
base = os.path.basename(filename)