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