1b815c7f3Sopenharmony_ci#!/bin/sh 2b815c7f3Sopenharmony_ci 3b815c7f3Sopenharmony_ciif git rev-parse --verify HEAD >/dev/null 2>&1 ; then 4b815c7f3Sopenharmony_ci against=HEAD 5b815c7f3Sopenharmony_cielse 6b815c7f3Sopenharmony_ci # Initial commit: diff against an empty tree object 7b815c7f3Sopenharmony_ci against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 8b815c7f3Sopenharmony_ci fi 9b815c7f3Sopenharmony_ci 10b815c7f3Sopenharmony_ci# Redirect output to stderr. 11b815c7f3Sopenharmony_ciexec 1>&2 12b815c7f3Sopenharmony_ci 13b815c7f3Sopenharmony_ci#------------------------------------------------------------------------------- 14b815c7f3Sopenharmony_ci# Prevent files with non-ascii filenames from being committed. 15b815c7f3Sopenharmony_ci 16b815c7f3Sopenharmony_ciif test $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 ; then 17b815c7f3Sopenharmony_ci echo "Error: Attempt to add a non-ascii file name." 18b815c7f3Sopenharmony_ci echo 19b815c7f3Sopenharmony_ci echo "This can cause problems if you want to work" 20b815c7f3Sopenharmony_ci echo "with people on other platforms." 21b815c7f3Sopenharmony_ci echo 22b815c7f3Sopenharmony_ci echo "To be portable it is advisable to rename the file ..." 23b815c7f3Sopenharmony_ci echo 24b815c7f3Sopenharmony_ci echo "Commit aborted." 25b815c7f3Sopenharmony_ci exit 1 26b815c7f3Sopenharmony_ci fi 27b815c7f3Sopenharmony_ci 28b815c7f3Sopenharmony_ci#------------------------------------------------------------------------------- 29b815c7f3Sopenharmony_ci# Check the formatting of all C files. 30b815c7f3Sopenharmony_ci 31b815c7f3Sopenharmony_ci# http://man.openbsd.org/sed#r 32b815c7f3Sopenharmony_ci# http://man.openbsd.org/sed#E 33b815c7f3Sopenharmony_ci# http://netbsd.gw.com/cgi-bin/man-cgi?sed++NetBSD-current 34b815c7f3Sopenharmony_ci# https://github.com/freebsd/freebsd/blob/master/usr.bin/sed/main.c 35b815c7f3Sopenharmony_ci# http://git.savannah.gnu.org/gitweb/?p=sed.git;a=blob;f=sed/sed.c 36b815c7f3Sopenharmony_ci# GNU has -r and -E (undocumented); MacOS has -E but not -r; Sunos has neither. 37b815c7f3Sopenharmony_cifiles=$(git diff-index --name-status --cached HEAD | grep -v ^D | sed -E "s/^[A-Z]+[A-Z0-9]*[ \t]+/ /") 38b815c7f3Sopenharmony_ci 39b815c7f3Sopenharmony_cicfiles="" 40b815c7f3Sopenharmony_cifor f in $files ; do 41b815c7f3Sopenharmony_ci if test `dirname $f` = "src/ALAC" ; then 42b815c7f3Sopenharmony_ci echo "Skipping cstyle checking on $f" 43b815c7f3Sopenharmony_ci elif test `echo $f | grep -c "\.[ch]$"` -gt 0 ; then 44b815c7f3Sopenharmony_ci cfiles="$cfiles $f" 45b815c7f3Sopenharmony_ci fi 46b815c7f3Sopenharmony_ci done 47b815c7f3Sopenharmony_ci 48b815c7f3Sopenharmony_ciif test -n "$cfiles" ; then 49b815c7f3Sopenharmony_ci Scripts/cstyle.py $cfiles 50b815c7f3Sopenharmony_ci if test $? -ne 0 ; then 51b815c7f3Sopenharmony_ci echo 52b815c7f3Sopenharmony_ci echo "Commit aborted. Fix the above error before trying again." 53b815c7f3Sopenharmony_ci exit 1 54b815c7f3Sopenharmony_ci fi 55b815c7f3Sopenharmony_ci fi 56b815c7f3Sopenharmony_ci 57b815c7f3Sopenharmony_ci#------------------------------------------------------------------------------- 58b815c7f3Sopenharmony_ci# Check the copyright notice of all files to be commited. 59b815c7f3Sopenharmony_ci 60b815c7f3Sopenharmony_ciuser=`git config --global user.email` 61b815c7f3Sopenharmony_ciyear=`date +"%Y"` 62b815c7f3Sopenharmony_ci 63b815c7f3Sopenharmony_cimissing_copyright_year="" 64b815c7f3Sopenharmony_ciif test $user = "erikd@mega-nerd.com" ; then 65b815c7f3Sopenharmony_ci for f in $files ; do 66b815c7f3Sopenharmony_ci if test `head -5 $f | grep -i copyright | grep -c -i $user` -gt 0 ; then 67b815c7f3Sopenharmony_ci user_copyright=`grep -i copyright $f | grep $user | grep -c $year` 68b815c7f3Sopenharmony_ci if test $user_copyright -lt 1 ; then 69b815c7f3Sopenharmony_ci missing_copyright_year="$missing_copyright_year $f" 70b815c7f3Sopenharmony_ci fi 71b815c7f3Sopenharmony_ci fi 72b815c7f3Sopenharmony_ci done 73b815c7f3Sopenharmony_ci fi 74b815c7f3Sopenharmony_ci 75b815c7f3Sopenharmony_ciif test -n "$missing_copyright_year" ; then 76b815c7f3Sopenharmony_ci echo "Missing current year in the copyright notice of the following files:" 77b815c7f3Sopenharmony_ci for f in $missing_copyright_year ; do 78b815c7f3Sopenharmony_ci echo " $f" 79b815c7f3Sopenharmony_ci done 80b815c7f3Sopenharmony_ci echo "Commit aborted." 81b815c7f3Sopenharmony_ci exit 1 82b815c7f3Sopenharmony_ci fi 83b815c7f3Sopenharmony_ci 84b815c7f3Sopenharmony_ciexit 0 85