Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/checkyear.js98
-rw-r--r--contrib/checkyear.sh62
2 files changed, 62 insertions, 98 deletions
diff --git a/contrib/checkyear.js b/contrib/checkyear.js
deleted file mode 100644
index afc38f4b0..000000000
--- a/contrib/checkyear.js
+++ /dev/null
@@ -1,98 +0,0 @@
-/* This script is a local pre-commit hook script.
- * It's used to check whether the copyright year of modified files has been
- * bumped up to the current (2013) year.
- *
- * Taken from TortoiseSVN repository, adapted for MPC-HC by thevbm
- *
- * Only *.cpp and *.h files are checked
- *
- * Set the local hook scripts like this (pre-commit hook):
- * WScript path/to/this/script/file.js
- * and set "Wait for the script to finish"
- */
-
-var ForReading = 1;
-var objArgs, num;
-
-objArgs = WScript.Arguments;
-num = objArgs.length;
-if (num !== 4)
-{
- WScript.Echo("Usage: [CScript | WScript] checkyear.js path/to/pathsfile depth path/to/messagefile path/to/CWD");
- WScript.Quit(1);
-}
-
-var re = /^(.+)(2006-2013)(.+)/;
-var basere = /^(.+)see\sAuthors.txt/;
-var filere = /(\.cpp$)|(\.h$)|(\.bat$)|(\.iss$)/;
-var found = true;
-var fs, a, rv, r;
-fs = new ActiveXObject("Scripting.FileSystemObject");
-// remove the quotes
-var files = readPaths(objArgs(0));
-// going backwards with while is believed to be faster
-var fileindex = files.length;
-var errormsg = "";
-
-while (fileindex--)
-{
- var f = files[fileindex];
- if (f.match(filere) !== null)
- {
- if (fs.FileExists(f))
- {
- a = fs.OpenTextFile(f, ForReading, false);
- var copyrightFound = false;
- var yearFound = false;
- while ((!a.AtEndOfStream) && (!yearFound))
- {
- r = a.ReadLine();
- rv = r.match(basere);
- if (rv !== null)
- {
- rv = r.match(re);
- if (rv !== null)
- yearFound = true;
-
- copyrightFound = true;
- }
- }
- a.Close();
-
- if (copyrightFound && (!yearFound))
- {
- if (errormsg !== "")
- errormsg += "\n";
- errormsg += f;
- found = false;
- }
- }
- }
-}
-
-if (found === false)
-{
- errormsg = "the file(s):\n" + errormsg + "\nhave not the correct copyright year!";
- WScript.stderr.writeLine(errormsg);
-}
-
-WScript.Quit(!found);
-
-
-// readFileLines
-function readPaths(path)
-{
- var retPaths = new Array();
- var fs = new ActiveXObject("Scripting.FileSystemObject");
- if (fs.FileExists(path))
- {
- var a = fs.OpenTextFile(path, ForReading);
- while (!a.AtEndOfStream)
- {
- var line = a.ReadLine();
- retPaths.push(line);
- }
- a.Close();
- }
- return retPaths;
-}
diff --git a/contrib/checkyear.sh b/contrib/checkyear.sh
new file mode 100644
index 000000000..10db8d45b
--- /dev/null
+++ b/contrib/checkyear.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+# (C) 2013 see Authors.txt
+#
+# This file is part of MPC-HC.
+#
+# MPC-HC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# MPC-HC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+
+# pre-commit hook to check if all changed and added files
+# have the current year as copyright information.
+
+# to enable the hook, copy this file to .git/hooks/pre-commit (no extension)
+
+year=$(date +%Y)
+pattern1='\(C\) ([0-9][0-9][0-9][0-9]-)?[0-9][0-9][0-9][0-9] see Authors.txt'
+pattern2='\(C\) ([0-9][0-9][0-9][0-9]-)?'"$year"' see Authors.txt'
+extensions=(cpp h)
+
+valid_extension() { for e in "${extensions[@]}"; do [[ "$e" == "$1" ]] && return 0; done; return 1; }
+
+# save output to variable, because MSYS bash doesn't support command substitution
+list=$(git diff --cached --name-only --diff-filter=ACMR)
+
+# loop through all new and modified files
+error=0
+while read -r f; do
+ # check if the file has an extension that we care about
+ if valid_extension "${f##*.}"; then
+ # only verify year if it already has an mpc-hc style copyright entry
+ if grep -q -E "$pattern1" "$f"; then
+ # check if the year is outdated
+ if ! grep -q -E "$pattern2" "$f"; then
+ # print filename
+ echo "$f"
+ # make sure we exit nonzero, later
+ error=1
+ fi
+ fi
+ fi
+done <<< "$list"
+
+# if there were files with outdated copyright, exit nonzero
+if (( error == 1 )); then
+ echo "Copyright year in the file(s) listed above is outdated!"
+ echo "To ignore this and commit anyways use 'git commit --no-verify'"
+ exit 1
+fi
+
+# all files valid
+exit 0