Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically checking copyright dates in copyright notices #231

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions tool/check-copyright-dates
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/sh
# tool/check-copyright-dates -- check copyrights dates are consistent with Git dates
# Richard Brooksby, Ravenbrook Limited, 2023-03-23
#
# Copyright (c) 2023 Ravenbrook Limited. See end of file for license.
#
# Only works for Ravenbrook copyrights. TODO: Should perhaps look for
# the last notice in a group of lines.

this_year="$(date '+%Y')"

{
find . -path './.git' -prune -o \
-type f ! -name '*~' ! -name '#*#' -print |
# git ls-tree -r --name-only HEAD |
while read -r path; do
# Skip binary files
if ! file --brief -- "$path" | grep -q 'text'; then continue; fi

# Debugging output
# echo 1>&2 "$path: checking..."

# Ask Git for the year of the last commit to the file
author_year=$(git log -1 --format="%ai" "$path" |
sed --silent --regexp-extended \
--expression='s/^([[:digit:]]{4})-.*$/\1/p')

# ``git log`` has empty output if the file is not in Git
if test -z "$author_year"; then
author_year=0
fi

# Search for copyright notices and extract the end years
nl < "$path" |
sed --silent --regexp-extended \
--expression='s/^[[:space:]]*([[:digit:]]+)[[:space:]].*Copyright[[:space:]]+(.*[[:space:]]+)?([[:digit:]]{4}[[:space:]]*-[[:space:]]*)?([[:digit:]]{4})[[:space:]]+Ravenbrook[[:space:]].*$/\1 \4/p' |
while read -r line end_year; do
if test "$end_year" -eq "$author_year"; then
continue
elif test "$author_year" -eq 0 -a "$end_year" -eq "$this_year"; then
continue
fi
echo "$path $line $author_year $end_year"
done
done
} | {
code=0
while read -r path line author_year end_year; do
code=1
if test "$author_year" -ne 0; then
year="Git author year $author_year"
else
year="this year $this_year"
fi
echo 1>&2 "$path:$line: Copyright end year $end_year does not match $year"
done
exit $code
}

# A. REFERENCES
#
# [None]
#
#
# B. DOCUMENT HISTORY
#
# 2023-03-23 RB Created in response to review brainstorm <https://github.com/Ravenbrook/mps/pull/179#issuecomment-1481486144>.
#
#
# C. COPYRIGHT AND LICENSE
#
# Copyright (C) 2023 Ravenbrook Limited <https://www.ravenbrook.com/>.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# $Id$