diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2014-04-17 17:05:35 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-04-17 17:05:35 +0100 |
commit | 29bf8404beb1bac3443393753660d77c587ed77c (patch) | |
tree | b0dce097a796900819668b8572df290dd8bcbbed | |
parent | 74540d9e0e097ffce9b56ffe4ac30caea76f7b76 (diff) | |
parent | 72a420f09835a31eb1ec097f2791a7603120a2d9 (diff) | |
download | morph-29bf8404beb1bac3443393753660d77c587ed77c.tar.gz |
Merge remote-tracking branch 'origin/baserock/richardmaw/style-checker'
Reviewed-by: Lars Wirzenius
Reviewed-by: Daniel Silverstone
-rwxr-xr-x | check | 5 | ||||
-rwxr-xr-x | scripts/check-copyright-year | 23 |
2 files changed, 23 insertions, 5 deletions
@@ -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' | 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): |