mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
coding style: experimental use of a clang-format git pre-commit hook to use code convention
This commit is contained in:
parent
7247525fb9
commit
ed1bac10cf
5 changed files with 130 additions and 9 deletions
64
.clang-format
Normal file
64
.clang-format
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
---
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: true
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: false
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
||||
IndentCaseLabels: false
|
||||
IndentFunctionDeclarationAfterType: false
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
Language: Cpp
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
TabWidth: 4
|
||||
UseTab: Always
|
||||
...
|
||||
51
.git-pre-commit
Executable file
51
.git-pre-commit
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
#!/bin/bash
|
||||
|
||||
# This hook purpose is to keep coding style consistent between all developers
|
||||
# It is automatically installed in .git/hooks folder by cmake on first run.
|
||||
|
||||
# From https://github.com/tatsuhiro-t/nghttp2/blob/master/pre-commit
|
||||
|
||||
function invalid-format-detected {
|
||||
cat git-clang-format.diff
|
||||
echo "*****************"
|
||||
echo "$0: Invalid coding style detected (see git-clang-format.diff for issues). Please correct it using one of the following:"
|
||||
echo "1) Apply patch located at git-clang-format.diff using:"
|
||||
echo " cd $(git rev-parse --show-toplevel) && $1"
|
||||
echo "2) Use clang-format to correctly format source code using:"
|
||||
echo " $2"
|
||||
echo "3) Reformat these lines manually."
|
||||
echo "*** Aborting commit.***"
|
||||
exit 1
|
||||
}
|
||||
function git-clang-format-diffing {
|
||||
format_diff=$(which git-clang-format)
|
||||
format_diff_options="--style=file"
|
||||
|
||||
#only diffing commited files, ignored staged one
|
||||
$format_diff $format_diff_options --diff $(git --no-pager diff --cached --name-status | grep -v '^D' | cut -f2) > git-clang-format.diff
|
||||
|
||||
if ! grep -q -E '(no modified files to format|clang-format did not modify any files)' git-clang-format.diff; then
|
||||
invalid-format-detected "git apply git-clang-format.diff" "clang-format $format_diff_options -i <some_file.c>"
|
||||
fi
|
||||
}
|
||||
|
||||
function clang-format-diff-diffing {
|
||||
format_diff=$(find /usr/bin/ -name 'clang-format-diff*' -type f | tail -n1)
|
||||
format_diff_options="-style file"
|
||||
|
||||
git diff-index --cached --diff-filter=ACMR -p HEAD -- | $format_diff $format_diff_options -p1 > git-clang-format.diff
|
||||
if [ -s git-clang-format.diff ]; then
|
||||
invalid-format-detected "patch -p0 < git-clang-format.diff" "${format_diff/-diff/} $format_diff_options -i <some_file.cpp>"
|
||||
fi
|
||||
}
|
||||
|
||||
set -e
|
||||
if which git-clang-format &>/dev/null; then
|
||||
git-clang-format-diffing $@
|
||||
elif [ ! -z "$(find /usr/bin/ /usr/local/bin/ /opt/bin/ -name 'clang-format-diff*' -type f 2>/dev/null)" ]; then
|
||||
# Warning! We need at least version 1.6...
|
||||
clang-format-diff-diffing $@
|
||||
else
|
||||
echo "$0: Please install clang-format (coding style checker) - could not find git-clang-format nor clang-format-diff in PATH. Skipping code verification..."
|
||||
exit 0
|
||||
fi
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -90,6 +90,5 @@ tester/record-call_with_file_player.wav
|
|||
tester/ZIDCache*.xml
|
||||
|
||||
tester/stereo-record.wav
|
||||
coreapi/bellesip_sal/.dirstamp
|
||||
coreapi/ldap/.dirstamp
|
||||
|
||||
.dirstamp
|
||||
git-clang-format.diff
|
||||
|
|
|
|||
17
autogen.sh
17
autogen.sh
|
|
@ -17,18 +17,18 @@ else
|
|||
fi
|
||||
|
||||
if test -f /opt/local/bin/glibtoolize ; then
|
||||
# darwin
|
||||
LIBTOOLIZE=/opt/local/bin/glibtoolize
|
||||
# darwin
|
||||
LIBTOOLIZE=/opt/local/bin/glibtoolize
|
||||
else
|
||||
LIBTOOLIZE=libtoolize
|
||||
LIBTOOLIZE=libtoolize
|
||||
fi
|
||||
|
||||
if test -d /opt/local/share/aclocal ; then
|
||||
ACLOCAL_ARGS="-I /opt/local/share/aclocal"
|
||||
ACLOCAL_ARGS="-I /opt/local/share/aclocal"
|
||||
fi
|
||||
|
||||
if test -d /share/aclocal ; then
|
||||
ACLOCAL_ARGS="$ACLOCAL_ARGS -I /share/aclocal"
|
||||
ACLOCAL_ARGS="$ACLOCAL_ARGS -I /share/aclocal"
|
||||
fi
|
||||
|
||||
INTLTOOLIZE=$(which intltoolize)
|
||||
|
|
@ -49,6 +49,13 @@ $AUTOMAKE --force-missing --add-missing --copy
|
|||
autoconf
|
||||
|
||||
set +x
|
||||
|
||||
#install git pre-commit hooks if possible
|
||||
if [ -d .git/hooks ] && [ ! -f .git/hooks/pre-commit ]; then
|
||||
cp .git-pre-commit .git/hooks/pre-commit
|
||||
chmod +x .git/hooks/pre-commit
|
||||
fi
|
||||
|
||||
if [ "$srcdir" = "." ]; then
|
||||
if [ -x oRTP/autogen.sh ]; then
|
||||
echo "Generating build scripts in oRTP..."
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 40eedaea06eb52b20ceab6de86de0a251be007e7
|
||||
Subproject commit 51ec0ba6cc09107d90340875dfb418d3a5e18245
|
||||
Loading…
Add table
Reference in a new issue