From 34cd0c29f63addd509107c9aefc7b7eeed4b9361 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Tue, 8 Oct 2024 11:16:20 +0200 Subject: [PATCH 1/3] clang-format: don't enforce the column limit The current value for the column limit is set to 80. While this is as expected, we often prefer readability over this strict limit. This means it is common to find code which extends over 80 characters. So let's change the column limit to be 0 instead. This ensures that the formatter doesn't complain about code strictly not following the column limit. Signed-off-by: Karthik Nayak --- .clang-format | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 41969eca4b7459..38910a3a538c18 100644 --- a/.clang-format +++ b/.clang-format @@ -12,7 +12,11 @@ UseTab: Always TabWidth: 8 IndentWidth: 8 ContinuationIndentWidth: 8 -ColumnLimit: 80 + +# While we recommend keeping column limit to 80, we don't want to +# enforce it as we generally are more lenient with this rule and +# prefer to prioritize readability. +ColumnLimit: 0 # C Language specifics Language: Cpp From 3557012fea5ed818dc58d8b8297b99faf6aa3b43 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Tue, 8 Oct 2024 11:19:52 +0200 Subject: [PATCH 2/3] clang-format: don't align expressions after linebreaks We enforce alignment of expressions after linebreaks. Which means for code such as return a || b; it will expect: return a || b; we instead want 'b' to be indent with tabs, which is already done by the 'ContinuationIndentWidth' variable. So let's explicitly set 'AlignOperands' to false. Signed-off-by: Karthik Nayak --- .clang-format | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.clang-format b/.clang-format index 38910a3a538c18..af12a038f717f3 100644 --- a/.clang-format +++ b/.clang-format @@ -43,10 +43,9 @@ AlignConsecutiveDeclarations: false # int cccccccc; AlignEscapedNewlines: Left -# Align operands of binary and ternary expressions -# int aaa = bbbbbbbbbbb + -# cccccc; -AlignOperands: true +# Don't enforce alignment after linebreaks and instead +# rely on the ContinuationIndentWidth value. +AlignOperands: false # Don't align trailing comments # int a; // Comment a From 1a6221f1a28c0f4d03d8fb2b93622f4f81acca28 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 9 Oct 2024 01:19:11 +0200 Subject: [PATCH 3/3] test --- block-sha1/sha1.h | 1 + ci/install-dependencies.sh | 1 + loose.c | 7 +++---- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/block-sha1/sha1.h b/block-sha1/sha1.h index 47bb9166368a70..72997cabfb8a25 100644 --- a/block-sha1/sha1.h +++ b/block-sha1/sha1.h @@ -21,4 +21,5 @@ void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx); #define platform_SHA1_Init blk_SHA1_Init #define platform_SHA1_Update blk_SHA1_Update #define platform_SHA1_Final blk_SHA1_Final +#define platform_SHA1_Test blk_SHA1_Test #endif diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh index 08656a15308ada..0190557672cf86 100755 --- a/ci/install-dependencies.sh +++ b/ci/install-dependencies.sh @@ -102,6 +102,7 @@ case "$jobname" in ClangFormat) sudo apt-get -q update sudo apt-get -q -y install clang-format + clang-format -version ;; StaticAnalysis) sudo apt-get -q update diff --git a/loose.c b/loose.c index 6d6a41b7e55a95..897ba389daa18c 100644 --- a/loose.c +++ b/loose.c @@ -1,10 +1,9 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "hash.h" #include "path.h" #include "object-store.h" #include "hex.h" +#include "repository.h" #include "wrapper.h" #include "gettext.h" #include "loose.h" @@ -142,8 +141,8 @@ int repo_write_loose_object_map(struct repository *repo) for (; iter != kh_end(map); iter++) { if (kh_exist(map, iter)) { - if (oideq(&kh_key(map, iter), the_hash_algo->empty_tree) || - oideq(&kh_key(map, iter), the_hash_algo->empty_blob)) + if (oideq(&kh_key(map, iter), repo->hash_algo->empty_tree) || + oideq(&kh_key(map, iter), repo->hash_algo->empty_blob)) continue; strbuf_addf(&buf, "%s %s\n", oid_to_hex(&kh_key(map, iter)), oid_to_hex(kh_value(map, iter))); if (write_in_full(fd, buf.buf, buf.len) < 0)