Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / common / hooks / pre-commit.hook
1 #!/bin/sh
2 #
3 # Check that the code follows a consistant code style
4 #
5
6 # Check for existence of indent, and error out if not present.
7 # On some *bsd systems the binary seems to be called gnunindent,
8 # so check for that first.
9
10 version=`gnuindent --version 2>/dev/null`
11 if test "x$version" = "x"; then
12   version=`indent --version 2>/dev/null`
13   if test "x$version" = "x"; then
14     echo "GStreamer git pre-commit hook:"
15     echo "Did not find GNU indent, please install it before continuing."
16     exit 1
17   fi
18   INDENT=indent
19 else
20   INDENT=gnuindent
21 fi
22
23 case `$INDENT --version` in
24   GNU*)
25       ;;
26   default)
27       echo "GStreamer git pre-commit hook:"
28       echo "Did not find GNU indent, please install it before continuing."
29       echo "(Found $INDENT, but it doesn't seem to be GNU indent)"
30       exit 1
31       ;;
32 esac
33
34 INDENT_PARAMETERS="--braces-on-if-line \
35         --case-brace-indentation0 \
36         --case-indentation2 \
37         --braces-after-struct-decl-line \
38         --line-length80 \
39         --no-tabs \
40         --cuddle-else \
41         --dont-line-up-parentheses \
42         --continuation-indentation4 \
43         --honour-newlines \
44         --tab-size8 \
45         --indent-level2 \
46         --leave-preprocessor-space"
47
48 echo "--Checking style--"
49 for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.c$"` ; do
50     # nf is the temporary checkout. This makes sure we check against the
51     # revision in the index (and not the checked out version).
52     nf=`git checkout-index --temp ${file} | cut -f 1`
53     newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
54     $INDENT ${INDENT_PARAMETERS} \
55         $nf -o $newfile 2>> /dev/null
56     # FIXME: Call indent twice as it tends to do line-breaks
57     # different for every second call.
58     $INDENT ${INDENT_PARAMETERS} \
59         $newfile 2>> /dev/null
60     diff -u -p "${nf}" "${newfile}"
61     r=$?
62     rm "${newfile}"
63     rm "${nf}"
64     if [ $r != 0 ] ; then
65 echo "================================================================================================="
66 echo " Code style error in: $file                                                                      "
67 echo "                                                                                                 "
68 echo " Please fix before committing. Don't forget to run git add before trying to commit again.        "
69 echo " If the whole file is to be committed, this should work (run from the top-level directory):      "
70 echo "                                                                                                 "
71 echo "   gst-indent $file; git add $file; git commit"
72 echo "                                                                                                 "
73 echo "================================================================================================="
74         exit 1
75     fi
76 done
77 echo "--Checking style pass--"