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