aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-07-14 11:19:26 -0700
committerJunio C Hamano <gitster@pobox.com>2025-07-14 11:19:26 -0700
commit38349d1160272bc685548b7a86b1d7c8ee536bad (patch)
treee29aa5302665eb011e81013e705c1d78fd11f408
parenta35b8c8b9e4609351316239cf31835803c7aa452 (diff)
parent3f7e447aaf40724e54fe81c99bee104829e3d23d (diff)
downloadgit-38349d1160272bc685548b7a86b1d7c8ee536bad.tar.gz
Merge branch 'kn/clang-format-updates'
Update ".clang-format" and ".editorconfig" to match our style guide a bit better. * kn/clang-format-updates: meson: add rule to run 'git clang-format' clang-format: add 'RemoveBracesLLVM' to the main config clang-format: set 'ColumnLimit' to 0
-rw-r--r--.clang-format27
-rwxr-xr-xci/run-style-check.sh18
-rw-r--r--meson.build12
3 files changed, 28 insertions, 29 deletions
diff --git a/.clang-format b/.clang-format
index 9547fe1b77..dcfd0aad60 100644
--- a/.clang-format
+++ b/.clang-format
@@ -12,7 +12,15 @@ UseTab: Always
TabWidth: 8
IndentWidth: 8
ContinuationIndentWidth: 8
-ColumnLimit: 80
+
+# While we do want to enforce a character limit of 80 characters, we often
+# allow lines to overflow that limit to prioritize readability. Setting a
+# character limit here with penalties has been finicky and creates too many
+# false positives.
+#
+# NEEDSWORK: It would be nice if we can find optimal settings to ensure we
+# can re-enable the limit here.
+ColumnLimit: 0
# C Language specifics
Language: Cpp
@@ -210,16 +218,11 @@ MaxEmptyLinesToKeep: 1
# No empty line at the start of a block.
KeepEmptyLinesAtTheStartOfBlocks: false
-# Penalties
-# This decides what order things should be done if a line is too long
-PenaltyBreakAssignment: 5
-PenaltyBreakBeforeFirstCallParameter: 5
-PenaltyBreakComment: 5
-PenaltyBreakFirstLessLess: 0
-PenaltyBreakOpenParenthesis: 300
-PenaltyBreakString: 5
-PenaltyExcessCharacter: 10
-PenaltyReturnTypeOnItsOwnLine: 300
-
# Don't sort #include's
SortIncludes: false
+
+# Remove optional braces of control statements (if, else, for, and while)
+# according to the LLVM coding style. This avoids braces on simple
+# single-statement bodies of statements but keeps braces if one side of
+# if/else if/.../else cascade has multi-statement body.
+RemoveBracesLLVM: true
diff --git a/ci/run-style-check.sh b/ci/run-style-check.sh
index 6cd4b1d934..0832c19df0 100755
--- a/ci/run-style-check.sh
+++ b/ci/run-style-check.sh
@@ -5,21 +5,5 @@
baseCommit=$1
-# Remove optional braces of control statements (if, else, for, and while)
-# according to the LLVM coding style. This avoids braces on simple
-# single-statement bodies of statements but keeps braces if one side of
-# if/else if/.../else cascade has multi-statement body.
-#
-# As this rule comes with a warning [1], we want to experiment with it
-# before adding it in-tree. since the CI job for the style check is allowed
-# to fail, appending the rule here allows us to validate its efficacy.
-# While also ensuring that end-users are not affected directly.
-#
-# [1]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removebracesllvm
-{
- cat .clang-format
- echo "RemoveBracesLLVM: true"
-} >/tmp/clang-format-rules
-
-git clang-format --style=file:/tmp/clang-format-rules \
+git clang-format --style=file:.clang-format \
--diff --extensions c,h "$baseCommit"
diff --git a/meson.build b/meson.build
index c133bd54ea..eaa45b21ea 100644
--- a/meson.build
+++ b/meson.build
@@ -2133,6 +2133,18 @@ if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc'
alias_target('check-headers', hdr_check)
endif
+git_clang_format = find_program('git-clang-format', required: false, native: true)
+if git_clang_format.found()
+ run_target('style',
+ command: [
+ git_clang_format,
+ '--style', 'file',
+ '--diff',
+ '--extensions', 'c,h'
+ ]
+ )
+endif
+
foreach key, value : {
'DIFF': diff.full_path(),
'GIT_SOURCE_DIR': meson.project_source_root(),