summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Duponchelle <mathieu@centricular.com>2020-10-08 23:45:24 +0200
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>2020-10-08 21:48:55 +0000
commit5029335dcb088b44f6f2dd090994888beeb9b37b (patch)
treee939377d22d4ba7cb00c3190a6e9344ecfaea4ea
parent6d319f8e4914909e43f737a13c4f3a464f406655 (diff)
git: use our standard pre commit hook
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/162>
-rwxr-xr-xhooks/pre-commit.hook83
-rw-r--r--meson.build3
2 files changed, 86 insertions, 0 deletions
diff --git a/hooks/pre-commit.hook b/hooks/pre-commit.hook
new file mode 100755
index 0000000..6f17740
--- /dev/null
+++ b/hooks/pre-commit.hook
@@ -0,0 +1,83 @@
+#!/bin/sh
+#
+# Check that the code follows a consistent code style
+#
+
+# Check for existence of indent, and error out if not present.
+# On some *bsd systems the binary seems to be called gnunindent,
+# so check for that first.
+
+version=`gnuindent --version 2>/dev/null`
+if test "x$version" = "x"; then
+ version=`gindent --version 2>/dev/null`
+ if test "x$version" = "x"; then
+ version=`indent --version 2>/dev/null`
+ if test "x$version" = "x"; then
+ echo "GStreamer git pre-commit hook:"
+ echo "Did not find GNU indent, please install it before continuing."
+ exit 1
+ else
+ INDENT=indent
+ fi
+ else
+ INDENT=gindent
+ fi
+else
+ INDENT=gnuindent
+fi
+
+case `$INDENT --version` in
+ GNU*)
+ ;;
+ default)
+ echo "GStreamer git pre-commit hook:"
+ echo "Did not find GNU indent, please install it before continuing."
+ echo "(Found $INDENT, but it doesn't seem to be GNU indent)"
+ exit 1
+ ;;
+esac
+
+INDENT_PARAMETERS="--braces-on-if-line \
+ --case-brace-indentation0 \
+ --case-indentation2 \
+ --braces-after-struct-decl-line \
+ --line-length80 \
+ --no-tabs \
+ --cuddle-else \
+ --dont-line-up-parentheses \
+ --continuation-indentation4 \
+ --honour-newlines \
+ --tab-size8 \
+ --indent-level2 \
+ --leave-preprocessor-space"
+
+echo "--Checking style--"
+for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.c$"` ; do
+ # nf is the temporary checkout. This makes sure we check against the
+ # revision in the index (and not the checked out version).
+ nf=`git checkout-index --temp ${file} | cut -f 1`
+ newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
+ $INDENT ${INDENT_PARAMETERS} \
+ $nf -o $newfile 2>> /dev/null
+ # FIXME: Call indent twice as it tends to do line-breaks
+ # different for every second call.
+ $INDENT ${INDENT_PARAMETERS} \
+ $newfile 2>> /dev/null
+ diff -u -p "${nf}" "${newfile}"
+ r=$?
+ rm "${newfile}"
+ rm "${nf}"
+ if [ $r != 0 ] ; then
+echo "================================================================================================="
+echo " Code style error in: $file "
+echo " "
+echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
+echo " If the whole file is to be committed, this should work (run from the top-level directory): "
+echo " "
+echo " gst-indent $file; git add $file; git commit"
+echo " "
+echo "================================================================================================="
+ exit 1
+ fi
+done
+echo "--Checking style pass--"
diff --git a/meson.build b/meson.build
index 6bd6d1e..821aa30 100644
--- a/meson.build
+++ b/meson.build
@@ -211,3 +211,6 @@ if gst_version_nano == 0
endif
configure_file(output: 'config.h', configuration: cdata)
+
+python3 = import('python').find_installation()
+run_command(python3, '-c', 'import shutil; shutil.copy("hooks/pre-commit.hook", ".git/hooks/pre-commit")')