]> git.saurik.com Git - wxWidgets.git/blob - misc/scripts/svn/hooks/pre-commit
Exclude message catalogs from UTF-8 check.
[wxWidgets.git] / misc / scripts / svn / hooks / pre-commit
1 #!/bin/sh
2
3 REPOS="$1"
4 TXN="$2"
5
6 SVNLOOK=/usr/bin/svnlook
7
8 svnl() {
9 cmd=$1
10 shift
11 $SVNLOOK $cmd "$REPOS" -t "$TXN" $*
12 }
13
14 rc=0
15
16 # exclude all third-party files from consideration, we don't want to do any
17 # checks for them
18 #
19 # also exclude message catalog files as they may be not in UTF-8
20 all_changed_files=`svnl changed | \
21 grep "^[AU]" | \
22 sed 's/^....//' | \
23 egrep -v "locale/.*\.po$" | \
24 egrep -v "src/(tiff|regex|jpeg|stc/scintilla)" | \
25 egrep -v "_wrap.cpp"`
26
27 # analyze the changed files to find all non-binary and all source files
28 for f in $all_changed_files; do
29 mimetype=`svnl proplist -v $f |
30 fgrep "svn:mime-type" |
31 sed 's/^ svn:mime-type : //'`
32 case $mimetype in
33 ''|text/*)
34 ;;
35
36 *)
37 continue
38 ;;
39 esac
40
41 changed_text_files="$changed_text_files $f"
42
43 case $f in
44 *.cpp|*.h|*.py)
45 changed_sources="$changed_sources $f"
46 ;;
47 esac
48 done
49
50 for f in $changed_sources; do
51 if svnl cat $f | fgrep -q ' '; then
52 echo "Please remove TABs from $f before committing." >&2
53 rc=1
54 fi
55 done
56
57 for f in $changed_text_files; do
58 if ! svnl cat $f | iconv -f utf8 -t WCHAR_T > /dev/null; then
59 echo "File $f doesn't use UTF-8, please convert it before committing." >&2
60 echo "(or set svn:mime-type property correctly if the file is binary)." >&2
61 rc=1
62 fi
63 done
64
65 exit $rc
66