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