Skip to content

Commit

Permalink
checksrc: add COPYRIGHT year check
Browse files Browse the repository at this point in the history
The check for updated copyright year is currently not enforced on any
file but only on files edited and/or committed locally. This is due to
the amount of files which aren't updated with their correct copyright
year at the time of their respective commit.
  • Loading branch information
danielgustafsson committed Nov 23, 2018
1 parent 2e49610 commit 2e2098e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
49 changes: 44 additions & 5 deletions lib/checksrc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ sub scanfile {
open(R, "<$file") || die "failed to open $file";

my $incomment=0;
my $copyright=0;
my @copyright=();
checksrc_clear(); # for file based ignores
accept_violations();

Expand All @@ -330,9 +330,16 @@ sub scanfile {
checksrc($cmd, $line, $file, $l)
}

# check for a copyright statement
if(!$copyright && ($l =~ /copyright .* \d\d\d\d/i)) {
$copyright=1;
# check for a copyright statement and save the years
if($l =~ /\* +copyright .* \d\d\d\d/i) {
while($l =~ /([\d]{4})/g) {
push @copyright, {
year => $1,
line => $line,
col => index($l, $1),
code => $l
};
}
}

# detect long lines
Expand Down Expand Up @@ -650,9 +657,41 @@ sub scanfile {
$prevl = $ol;
}

if(!$copyright) {
# The check for updated copyrightyear is overly complicated in order to
# not punish current hacking for past sins. The copyright years are right
# now a bit behind, so enforcing copyright year checking on all files
# would cause hundreds of errors. Instead we only look at files which are
# tracked in the Git repo and edited in the workdir, or committed locally
# on the branch without being in upstream master.
#
# The simple and naive test is to simply check for the current year, but
# updating the year even without an edit is against project policy (and it
# would fail every file on January 1st).
#
# A rather more interesting, and correct, check would be to not test only
# locally committed files but inspect all files wrt the year of their last
# commit. Removing the `git rev-list origin/master..HEAD` condition below
# will enfore copyright year checks against the year the file was last
# committed (and thus edited to some degree).
my $commityear = undef;
@copyright = sort {$$b{year} cmp $$a{year}} @copyright;
if(!scalar(@copyright)) {
checkwarn("COPYRIGHT", 1, 0, $file, "", "Missing copyright statement", 1);
}
elsif(`git status -s -- $file` =~ /^ [MARCU]/) {
$commityear = (localtime(time))[5] + 1900;
}
elsif (`git rev-list --count origin/master..HEAD -- $file` !~ /^0/) {
my $grl = `git rev-list --max-count=1 --timestamp HEAD -- $file`;
$commityear = (localtime((split(/ /, $grl))[0]))[5] + 1900;
}

if(defined($commityear) && $copyright[0]{year}!= $commityear) {
checkwarn("COPYRIGHT", $copyright[0]{line}, $copyright[0]{col},
$file, $copyright[0]{code},
"Copyright year out of date, should be $commityear, is $copyright[0]{year}", 1);
}

if($incomment) {
checkwarn("OPENCOMMENT", 1, 0, $file, "", "Missing closing comment", 1);
}
Expand Down
1 change: 1 addition & 0 deletions lib/md4.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* !checksrc! disable COPYRIGHT
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
* MD4 Message-Digest Algorithm (RFC 1320).
*
Expand Down

0 comments on commit 2e2098e

Please sign in to comment.