From: Daniel Arndt Date: Wed, 30 May 2018 16:42:42 +0000 (+0200) Subject: Add clang-format git hook X-Git-Tag: v9.1.0-rc1~1022^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0f6cef99b199dd22f29a3526b23d39e551ac7ac;p=dealii.git Add clang-format git hook --- diff --git a/contrib/git-hooks/pre-commit b/contrib/git-hooks/pre-commit new file mode 100755 index 0000000000..36f86334fb --- /dev/null +++ b/contrib/git-hooks/pre-commit @@ -0,0 +1,37 @@ +#!/bin/bash +## --------------------------------------------------------------------- +## +## Copyright (C) 2012 - 2018 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# This pre-commit hook checks formatting for each commit. +# + +BASEDIR="$(git rev-parse --show-toplevel 2>/dev/null)" + +if [ ! -f "${BASEDIR}"/contrib/utilities/indent-branch ]; then + echo "*** This script must be run from within the deal.II git repository." + exit 1 +fi + +cd "${BASEDIR}" +OUTPUT="$(REPORT_ONLY=true "${BASEDIR}"/contrib/utilities/indent-branch)" + +if [ ! -z "${OUTPUT}" ]; then + echo "git commit aborted due to formatting issues:" + echo "${OUTPUT}" + echo "" + echo "Please run ./contrib/utilities/indent-branch to fix these issues and try again." + exit 1 +fi diff --git a/doc/doxygen/headers/coding_conventions.h b/doc/doxygen/headers/coding_conventions.h index 6e80667ed6..7cecc12ab0 100644 --- a/doc/doxygen/headers/coding_conventions.h +++ b/doc/doxygen/headers/coding_conventions.h @@ -54,7 +54,10 @@ style guidelines outlined in this page. Alternatively, you can run in whatever directory you set up the library to be compiled in to indent all -source files. +source files. If you want to make sure that the indenting is correct for all +your commits, you might want to set up a pre-commit hook. One way to do so, +is to copy ${SOURCE_DIR}/contrib/scripts/pre-commit-clang-format to +${SOURCE_DIR}/.git/hooks/pre-commit and make sure it is executable.

Style issues

@@ -75,7 +78,8 @@ source files.
  • In the implementation files, after each function, three empty lines are expected to enable better readability. One empty line occurs in functions to group blocks of code, since two empty lines are not enough to visibly - distinguish sufficiently that the code belongs to two different functions.
  • + distinguish sufficiently that the code belongs to two different + functions.
  • Whenever an integer variable can only assume nonnegative values, it is marked as unsigned. The same applies to functions that can only @@ -188,33 +192,35 @@ deal.II we adopt the following convention:

    1. If we can enumerate all possible template arguments (e.g., the dimension -can only be 1, 2, or 3), then a function template goes into the .cc file and -we explicitly instantiate all possibilities. Users will not have any need to -ever see these function templates because they will not want to instantiate -these functions for any other template arguments anyway.
    2. +can only be 1, 2, or 3), then a function template goes into the .cc +file and we explicitly instantiate all possibilities. Users will not have any +need to ever see these function templates because they will not want to +instantiate these functions for any other template arguments anyway.
    3. If we can not enumerate all possible template arguments (e.g., vector types -- because users might want to define their own vector kinds) but at least know a few common usage cases, then the function is put into a -.templates.h file. We #include it into the .cc file and instantiate the -functions for all of the common arguments. For almost all users, this will be -just fine -- they only use the (vector, matrix, ...) types we already -instantiate, and for them the .templates.h file will not be of any interest. -It will also not slow down their compilations because nothing they see will -#include the .templates.h file. But users who define their own -(vector, matrix, ...) types can instantiate the template functions with their -own user-defined types by including the .templates.h files. +.templates.h file. We #include it into the .cc file +and instantiate the functions for all of the common arguments. For almost all +users, this will be just fine -- they only use the (vector, matrix, ...) types +we already instantiate, and for them the .templates.h file will not +be of any interest. It will also not slow down their compilations because +nothing they see will #include the .templates.h file. But users who +define their own (vector, matrix, ...) types can instantiate the template +functions with their own user-defined types by including the +.templates.h files.
    4. Finally, if we can not assume in advance which values template arguments will take (e.g., any class derived from Subscriptor can be used as an argument), the definitions of functions are provided at the bottom of the header -file with declarations. The definitions should be guarded with #ifndef DOXYGEN ... -#endif to prevent Doxygen from picking them up.
    5. +file with declarations. The definitions should be guarded with #ifndef +DOXYGEN ... #endif to prevent Doxygen from picking them up.
    -

    For the first two cases, instantiation instructions are defined in .inst.in -files. They are processed by a binary called expand_instantiations (built from +

    For the first two cases, instantiation instructions are defined in +.inst.in files. They are processed by a binary called +expand_instantiations (built from cmake/scripts/expand_instantiations.cc) and the parameters are defined dynamically through cmake depending on your configuration (see share/deal.II/template-arguments in your build directory). @@ -438,7 +444,8 @@ we list here: ... // something lengthy and complicated for (cell = dof_handler.begin_active(); ...) { - const Point cell_center = (cell->vertex(0) + cell->vertex(1)) / 2; + const Point cell_center = (cell->vertex(0) + + cell->vertex(1)) / 2; ... }