From ccaab279edce467ccc12746415029b83e1048e98 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 19 Mar 2014 17:54:56 +0000 Subject: check-copyright-year: Use current date for uncommitted changes --- scripts/check-copyright-year | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/check-copyright-year b/scripts/check-copyright-year index 99a6df94..d72ddbc6 100755 --- a/scripts/check-copyright-year +++ b/scripts/check-copyright-year @@ -2,7 +2,7 @@ # # Does the copyright statement include the year of the latest git commit? # -# Copyright (C) 2012 Codethink Limited +# Copyright (C) 2012, 2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import datetime import re import cliapp @@ -33,23 +34,39 @@ class CheckCopyrightYear(cliapp.Application): def setup(self): self.all_ok = True + self.uncommitted = self.get_uncommitted_files() + self.this_year = datetime.datetime.now().year def cleanup(self): if not self.all_ok: raise cliapp.AppException('Some copyright years need fixing') + def get_uncommitted_files(self): + filenames = set() + status = self.runcmd(['git', 'status', '--porcelain', '-z']) + tokens = status.rstrip('\0').split('\0') + while tokens: + tok = tokens.pop(0) + filenames.add(tok[3:]) + if 'R' in tok[0:2]: + filenames.add(tokens.pop(0)) + return filenames + def process_input_line(self, filename, line): m = self.pat.match(line) if not m: return - year = self.get_git_commit_year(filename) + year = None + if filename not in self.uncommitted: + year = self.get_git_commit_year(filename) + if year is None: # git does not have a commit date for the file, which might # happen if the file isn't committed yet. This happens during # development, and it's OK. It's not quite a lumberjack, but # let's not get into gender stereotypes here. - return + year = self.this_year ok = False for start, end in self.get_copyright_years(m): -- cgit v1.2.1 From 72a420f09835a31eb1ec097f2791a7603120a2d9 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 19 Mar 2014 17:56:17 +0000 Subject: style check: Include newly added files in checks --- check | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/check b/check index a5ef4128..77d4e826 100755 --- a/check +++ b/check @@ -96,12 +96,13 @@ errors=0 if "$run_style" && [ -d .git ]; then echo "Checking copyright statements" - if ! (git ls-files -z | xargs -0r scripts/check-copyright-year); then + if ! (git ls-files --cached -z | + xargs -0r scripts/check-copyright-year); then errors=1 fi echo 'Checking source code for silliness' - if ! (git ls-files | + if ! (git ls-files --cached | grep -v '\.gz$' | grep -Ev 'tests[^/]*/.*\.std(out|err)' | grep -vF 'tests.build/build-system-autotools.script' | -- cgit v1.2.1