git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] clang-format: modify rules to reduce false-positives
@ 2025-06-25 16:43 Karthik Nayak
  2025-06-25 16:43 ` [PATCH 1/4] editorconfig: set maximum line length to 120 characters Karthik Nayak
                   ` (5 more replies)
  0 siblings, 6 replies; 36+ messages in thread
From: Karthik Nayak @ 2025-06-25 16:43 UTC (permalink / raw)
  To: git; +Cc: Christian Couder, Karthik Nayak

This series is in response to an email thread [1] around the usage of
'.clang-format' and its effectiveness.

The goal of the series is to improve the usage of 'clang-format' in the
repository. To do this we:
1. Reduce the number of false positives. Majority of which is due to
   line-wrapping. We remove the 'ColumnLimit' from 'clang-format'. This
   removes the responsibility of line-wrapping from 'clang-format' and puts
   it into the hands of the user.
2. Add a 120 character limit to the '.editorconfig' to ensure that
   editors wrap lines beyond that.
3. Add a rule to 'meson' to run 'git clang-format' by running 'meson
   compile style'.
4. Make the 'RemoveBracesLLVM' permanent by moving it to
   '.clang-format'.

With this, running `git clang-format` for the last 25 commits in master,
seems to produce much less false positives.

  diff --git a/builtin/diff.c b/builtin/diff.c
  index c6231edce4..246b81caa2 100644
  --- a/builtin/diff.c
  +++ b/builtin/diff.c
  @@ -30,14 +30,13 @@
   #define DIFF_NO_INDEX_IMPLICIT 2

   static const char builtin_diff_usage[] =
  -"git diff [<options>] [<commit>] [--] [<path>...]\n"
  -"   or: git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]\n"
  -"   or: git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]\n"
  -"   or: git diff [<options>] <commit>...<commit> [--] [<path>...]\n"
  -"   or: git diff [<options>] <blob> <blob>\n"
  -"   or: git diff [<options>] --no-index [--] <path> <path> [<pathspec>...]"
  -"\n"
  -COMMON_DIFF_OPTIONS_HELP;
  +	"git diff [<options>] [<commit>] [--] [<path>...]\n"
  +	"   or: git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]\n"
  +	"   or: git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]\n"
  +	"   or: git diff [<options>] <commit>...<commit> [--] [<path>...]\n"
  +	"   or: git diff [<options>] <blob> <blob>\n"
  +	"   or: git diff [<options>] --no-index [--] <path> <path> [<pathspec>...]"
  +	"\n" COMMON_DIFF_OPTIONS_HELP;

   static const char *blob_path(struct object_array_entry *entry)
   {
  diff --git a/builtin/stash.c b/builtin/stash.c
  index 7cd3ad8aa4..90e441a6e5 100644
  --- a/builtin/stash.c
  +++ b/builtin/stash.c
  @@ -1802,7 +1802,8 @@ static int push_stash(int argc, const char **argv, const char *prefix,

 		  argc = parse_options(argc, argv, prefix, options,
 				       push_assumed ? git_stash_usage :
  -				     git_stash_push_usage, flags);
  +						    git_stash_push_usage,
  +				     flags);
 		  force_assume |= patch_mode;
 	  }

  diff --git a/bundle-uri.c b/bundle-uri.c
  index c9d65aa0ce..89f59aafe8 100644
  --- a/bundle-uri.c
  +++ b/bundle-uri.c
  @@ -123,7 +123,7 @@ void print_bundle_list(FILE *fp, struct bundle_list *list)
 		  for (i = 0; i < BUNDLE_HEURISTIC__COUNT; i++) {
 			  if (heuristics[i].heuristic == list->heuristic) {
 				  fprintf(fp, "\theuristic = %s\n",
  -				       heuristics[list->heuristic].name);
  +					heuristics[list->heuristic].name);
 				  break;
 			  }
 		  }
  diff --git a/diff-no-index.c b/diff-no-index.c
  index 4aeeb98cfa..a3892a9ccc 100644
  --- a/diff-no-index.c
  +++ b/diff-no-index.c
  @@ -325,7 +325,7 @@ static int fixup_paths(const char **path, struct strbuf *replacement)
 	  return 0;
   }

  -static const char * const diff_no_index_usage[] = {
  +static const char *const diff_no_index_usage[] = {
 	  N_("git diff --no-index [<options>] <path> <path> [<pathspec>...]"),
 	  NULL
   };
  diff --git a/pathspec.h b/pathspec.h
  index 5e3a6f1fe7..601b9ca201 100644
  --- a/pathspec.h
  +++ b/pathspec.h
  @@ -80,7 +80,7 @@ struct pathspec {
    * For git diff --no-index, indicate that we are operating without
    * a repository or index.
    */
  -#define PATHSPEC_NO_REPOSITORY (1<<7)
  +#define PATHSPEC_NO_REPOSITORY (1 << 7)

   /**
    * Given command line arguments and a prefix, convert the input to

While now I'm tempted to mark the 'check-style' CI job as required. I
think we should do that in the future.

[1]: https://lore.kernel.org/git/xmqqmsa3adpw.fsf@gitster.g/

---
 .clang-format         | 27 +++++++++++++++------------
 .editorconfig         |  1 +
 ci/run-style-check.sh | 18 +-----------------
 meson.build           | 12 ++++++++++++
 4 files changed, 29 insertions(+), 29 deletions(-)

Karthik Nayak (4):
      editorconfig: set maximum line length to 120 characters
      clang-format: set 'ColumnLimit' to 0
      clang-format: add 'RemoveBracesLLVM' to the main config
      meson: add rule to run 'git clang-format'



base-commit: f0135a9047ca37d4d117dcf21f7e3e89fad85d00
change-id: 20250625-525-make-clang-format-more-robust-968126c991b9

Thanks
- Karthik


^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2025-07-02  9:23 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-25 16:43 [PATCH 0/4] clang-format: modify rules to reduce false-positives Karthik Nayak
2025-06-25 16:43 ` [PATCH 1/4] editorconfig: set maximum line length to 120 characters Karthik Nayak
2025-06-25 18:41   ` Junio C Hamano
2025-06-26  8:27     ` Karthik Nayak
2025-06-26 14:25       ` Junio C Hamano
2025-06-27  8:38         ` Karthik Nayak
2025-06-26 16:22   ` Justin Tobler
2025-06-27  8:51     ` Karthik Nayak
2025-06-27 15:12       ` Justin Tobler
2025-06-30  8:29         ` Karthik Nayak
2025-06-25 16:43 ` [PATCH 2/4] clang-format: set 'ColumnLimit' to 0 Karthik Nayak
2025-06-25 16:43 ` [PATCH 3/4] clang-format: add 'RemoveBracesLLVM' to the main config Karthik Nayak
2025-06-25 16:43 ` [PATCH 4/4] meson: add rule to run 'git clang-format' Karthik Nayak
2025-06-26 16:35   ` Justin Tobler
2025-06-27  8:12     ` Karthik Nayak
2025-06-27 14:25       ` Junio C Hamano
2025-06-30  8:34         ` Karthik Nayak
2025-06-30 15:24           ` Junio C Hamano
2025-06-30  8:38 ` [PATCH v2 0/3] clang-format: modify rules to reduce false-positives Karthik Nayak
2025-06-30  8:38   ` [PATCH v2 1/3] clang-format: set 'ColumnLimit' to 0 Karthik Nayak
2025-06-30  8:38   ` [PATCH v2 2/3] clang-format: add 'RemoveBracesLLVM' to the main config Karthik Nayak
2025-06-30  8:38   ` [PATCH v2 3/3] meson: add rule to run 'git clang-format' Karthik Nayak
2025-07-01 10:13     ` Patrick Steinhardt
2025-07-01 15:08       ` Karthik Nayak
2025-07-01 16:02       ` Junio C Hamano
2025-07-01 13:26     ` Toon Claes
2025-07-01 15:12       ` Karthik Nayak
2025-07-02  2:54         ` Patrick Steinhardt
2025-06-30 15:27   ` [PATCH v2 0/3] clang-format: modify rules to reduce false-positives Junio C Hamano
2025-07-01 13:36   ` Toon Claes
2025-07-01 15:19     ` Karthik Nayak
2025-07-01 20:49     ` Junio C Hamano
2025-07-02  9:23 ` [PATCH v3 " Karthik Nayak
2025-07-02  9:23   ` [PATCH v3 1/3] clang-format: set 'ColumnLimit' to 0 Karthik Nayak
2025-07-02  9:23   ` [PATCH v3 2/3] clang-format: add 'RemoveBracesLLVM' to the main config Karthik Nayak
2025-07-02  9:23   ` [PATCH v3 3/3] meson: add rule to run 'git clang-format' Karthik Nayak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).