For contributors, it would be quite helpful to have all of the proton-c code
formatted in a consistent style. A common OSS pattern these days is to
supply a .clang-format file at the top-level folder  of the C/C++ code base
which defines the style. This has the advantage when writing code, you don’t
need to think or worry about the coding style at all. Write it in yours,
then just run clang-format-3.5 before commit / submit of patch.

When I was working on patches I found the following .clang-format file gave
me the most similar style to what the majority of existing code was using:

BasedOnStyle: LLVM
UseTab: Never
IndentWidth: 2
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: false
DerivePointerAlignment: true
PointerAlignment: Right

i.e., based on the LLVM style, but adapted in such a way that the number of
modifications to the proton-c code base were minimal

This seemed to be born out by the diff stats:

# the built-in clang-format styles

 messenger.c => /tmp/messenger/chromium | 1503
++++++++++++++++----------------
 1 file changed, 765 insertions(+), 738 deletions(-)
 messenger.c => /tmp/messenger/google | 985
+++++++++++++++--------------------
 1 file changed, 432 insertions(+), 553 deletions(-)
 messenger.c => /tmp/messenger/llvm | 930
+++++++++++++++++--------------------
 1 file changed, 429 insertions(+), 501 deletions(-)
 messenger.c => /tmp/messenger/mozilla | 1034
+++++++++++++++------------------
 1 file changed, 480 insertions(+), 554 deletions(-)
 messenger.c => /tmp/messenger/webkit | 3655
+++++++++++++++++-----------------
 1 file changed, 1830 insertions(+), 1825 deletions(-)

# the custom style as per above

 messenger.c => /tmp/messenger/custom-style | 599
++++++++++++++++++++-----------------
 1 file changed, 329 insertions(+), 270 deletions(-)

If the move to a git-only development stream process goes ahead, then there
are various best practices of adding clang-format either as a pre-commit
hook, or as a plugin command (`git clang-format`). This can either be made
to reformat the entire file to match the style, or to only reformat the
lines that are being changed under the current commit (if you're concerned
about losing git-blame / git-annotate information, this is the best way to
gradually migrate)






--
View this message in context: 
http://qpid.2158936.n2.nabble.com/clang-format-for-proton-c-tp7616014.html
Sent from the Apache Qpid Proton mailing list archive at Nabble.com.

Reply via email to