git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re* [PATCH 1/8] clang-format: indent preprocessor directives after hash

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 8, 2024, 16:27 UTC
Message-ID
<xmqqa5irkfw3.fsf_-_@gitster.g>
In-Reply-To
<20240708092317.267915-2-karthik.188@gmail.com>
Subject: cpp: consistently write '#' for CPP directive at column 1

Besides it would get complaints from older compilers and look strange to older eyes that were trained with such compilers, we will be introducing a rule to be enforced to new code. Update a few existing violators before it happens.

The changes in git-compat-util.h and sha1dc/sha1.c are both about indenting the body of conditional CPP directives, e.g.,

    (correct)           (incorrect)
    #if foo             #if foo
    # define bar         #define bar
    #endif              #endif

The #define/#undef in pkt-line.c were indented not because they were inside a conditional compilation block inside #if/#endif but because they were added inside a function. As the function body is short, we can move them out of the function and lose their indentation without sacrificing the readability.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * So, if we decide to apply a preliminary clean-up to the codebase,
   it should look somethine like this.  I couldn't decide what we
   want to do with diff.h where the indentation is done for the same
   reason as how pkt-line.c temporarily defines hex(), but it is
   messier.
	diff --git i/diff.h w/diff.h
	index 9901c8ca8c..ecaa8ec49e 100644
	--- i/diff.h
	+++ w/diff.h
	@@ -386,12 +386,12 @@ struct diff_options {
	 		COLOR_MOVED_ZEBRA = 3,
	 		COLOR_MOVED_ZEBRA_DIM = 4,
	 	} color_moved;
	-	#define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
	-	#define COLOR_MOVED_MIN_ALNUM_COUNT 20
	+#define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
	+#define COLOR_MOVED_MIN_ALNUM_COUNT 20
	 
	 	/* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
	-	#define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
	-	#define COLOR_MOVED_WS_ERROR (1<<0)
	+#define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
	+#define COLOR_MOVED_WS_ERROR (1<<0)
	 	unsigned color_moved_ws_handling;
	 
	 	struct repository *repo;
  I _think_ the right solution for the first half of this is
  actually to define the enum outside the structure and define
  _DEFAULT and _COUNT next to the enum, all at the top-level of the
  header file outside "struct diff_options" definition.
  But I am unsure how to clean up the latter and that is where I
  stopped.
 git-compat-util.h | 2 +-
 pkt-line.c        | 4 ++--
 sha1dc/sha1.c     | 4 ++--
 4 files changed, 9 insertions(+), 9 deletions(-)
diff --git c/git-compat-util.h w/git-compat-util.h
index ca7678a379..2cbd7c92b8 100644
--- c/git-compat-util.h
+++ w/git-compat-util.h
@@ -41,7 +41,7 @@ struct strbuf;
 # define GIT_GNUC_PREREQ(maj, min) \
 	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
 #else
- #define GIT_GNUC_PREREQ(maj, min) 0
+# define GIT_GNUC_PREREQ(maj, min) 0
 #endif
 
 
diff --git c/pkt-line.c w/pkt-line.c
index 24479eae4d..30044b2e76 100644
--- c/pkt-line.c
+++ w/pkt-line.c
@@ -132,17 +132,17 @@ void packet_buf_delim(struct strbuf *buf)
 	strbuf_add(buf, "0001", 4);
 }
 
+#define hex(a) (hexchar[(a) & 15])
 void set_packet_header(char *buf, int size)
 {
 	static char hexchar[] = "0123456789abcdef";
 
-	#define hex(a) (hexchar[(a) & 15])
 	buf[0] = hex(size >> 12);
 	buf[1] = hex(size >> 8);
 	buf[2] = hex(size >> 4);
 	buf[3] = hex(size);
-	#undef hex
 }
+#undef hex
 
 static void format_packet(struct strbuf *out, const char *prefix,
 			  const char *fmt, va_list args)
diff --git c/sha1dc/sha1.c w/sha1dc/sha1.c
index f993ef9c69..e82e05425e 100644
--- c/sha1dc/sha1.c
+++ w/sha1dc/sha1.c
@@ -139,9 +139,9 @@
 #define sha1_mix(W, t)  (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1))
 
 #ifdef SHA1DC_BIGENDIAN
-	#define sha1_load(m, t, temp)  { temp = m[t]; }
+#	define sha1_load(m, t, temp)  { temp = m[t]; }
 #else
-	#define sha1_load(m, t, temp)  { temp = m[t]; sha1_bswap32(temp); }
+#	define sha1_load(m, t, temp)  { temp = m[t]; sha1_bswap32(temp); }
 #endif
 
 #define sha1_store(W, t, x)	*(volatile uint32_t *)&W[t] = x
Previous: Karthik NayakNext: Karthik Nayak
Message 6 of 127 in “clang-format: add more rules and enable on CI”
  1. 0/8 clang-format: add more rules and enable on CIKarthik Nayak, Jul 8, 2024
  2. 1/8 clang-format: indent preprocessor directives after hashKarthik Nayak, Jul 8, 2024
  3. Chris TorekJul 8, 2024
  4. Junio C HamanoJul 8, 2024
  5. Karthik NayakJul 8, 2024
  6. Re* [PATCH 1/8] clang-format: indent preprocessor directives after hashJunio C Hamano, Jul 8, 2024
  7. 2/8 clang-format: avoid spacing around bitfield colonKarthik Nayak, Jul 8, 2024
  8. 3/8 clang-format: ensure files end with newlinesKarthik Nayak, Jul 8, 2024
  9. Junio C HamanoJul 8, 2024
  10. 4/8 clang-format: replace deprecated option with 'SpacesInParens'Karthik Nayak, Jul 8, 2024
  11. Junio C HamanoJul 8, 2024
  12. 5/8 clang-format: avoid braces on simple single-statement bodiesKarthik Nayak, Jul 8, 2024
  13. Junio C HamanoJul 8, 2024
  14. Karthik NayakJul 8, 2024
  15. Phillip WoodJul 12, 2024
  16. Karthik NayakJul 13, 2024
  17. phillip.wood123@gmail.comJul 13, 2024
  18. Karthik NayakJul 13, 2024
  19. 6/8 clang-format: formalize some of the spacing rulesKarthik Nayak, Jul 8, 2024
  20. Junio C HamanoJul 8, 2024
  21. Karthik NayakJul 8, 2024
  22. Justin ToblerJul 8, 2024
  23. Karthik NayakJul 8, 2024
  24. Eric SunshineJul 8, 2024
  25. Karthik NayakJul 10, 2024
  26. 7/8 ci: run style check on GitHub and GitLabKarthik Nayak, Jul 8, 2024
  27. Junio C HamanoJul 8, 2024
  28. Karthik NayakJul 8, 2024
  29. Re* [PATCH 7/8] ci: run style check on GitHub and GitLabJunio C Hamano, Jul 8, 2024
  30. Justin ToblerJul 8, 2024
  31. brian m. carlsonJul 9, 2024
  32. Justin ToblerJul 8, 2024
  33. Karthik NayakJul 8, 2024
  34. Justin ToblerJul 9, 2024
  35. Karthik NayakJul 9, 2024
  36. Justin ToblerJul 9, 2024
  37. Karthik NayakJul 10, 2024
  38. 8/8 check-whitespace: detect if no base_commit is providedKarthik Nayak, Jul 8, 2024
  39. Chris TorekJul 8, 2024
  40. Georg PfuetzenreuterJul 8, 2024
  41. Chris TorekJul 8, 2024
  42. Karthik NayakJul 8, 2024
  43. Junio C HamanoJul 8, 2024
  44. Junio C HamanoJul 8, 2024
  45. Karthik NayakJul 10, 2024
  46. Junio C HamanoJul 10, 2024
  47. Karthik NayakJul 11, 2024
  48. Junio C HamanoJul 11, 2024
  49. Justin ToblerJul 8, 2024
  50. Karthik NayakJul 10, 2024
  51. Chris TorekJul 8, 2024
  52. 0/8 clang-format: add more rules and enable on CIKarthik Nayak, Jul 11, 2024
  53. 1/8 clang-format: indent preprocessor directives after hashKarthik Nayak, Jul 11, 2024
  54. 2/8 clang-format: avoid spacing around bitfield colonKarthik Nayak, Jul 11, 2024
  55. 3/8 clang-format: ensure files end with newlinesKarthik Nayak, Jul 11, 2024
  56. 4/8 clang-format: replace deprecated option with 'SpacesInParens'Karthik Nayak, Jul 11, 2024
  57. 5/8 clang-format: avoid braces on simple single-statement bodiesKarthik Nayak, Jul 11, 2024
  58. Junio C HamanoJul 11, 2024
  59. Karthik NayakJul 12, 2024
  60. Junio C HamanoJul 12, 2024
  61. Phillip WoodJul 12, 2024
  62. 6/8 clang-format: formalize some of the spacing rulesKarthik Nayak, Jul 11, 2024
  63. 8/8 check-whitespace: detect if no base_commit is providedKarthik Nayak, Jul 11, 2024
  64. Justin ToblerJul 11, 2024
  65. Junio C HamanoJul 11, 2024
  66. Karthik NayakJul 12, 2024
  67. Junio C HamanoJul 12, 2024
  68. 7/8 ci: run style check on GitHub and GitLabKarthik Nayak, Jul 11, 2024
  69. Junio C HamanoJul 11, 2024
  70. 0/8 clang-format: add more rules and enable on CIKarthik Nayak, Jul 13, 2024
  71. 1/8 clang-format: indent preprocessor directives after hashKarthik Nayak, Jul 13, 2024
  72. 2/8 clang-format: avoid spacing around bitfield colonKarthik Nayak, Jul 13, 2024
  73. 3/8 clang-format: ensure files end with newlinesKarthik Nayak, Jul 13, 2024
  74. 4/8 clang-format: replace deprecated option with 'SpacesInParens'Karthik Nayak, Jul 13, 2024
  75. 5/8 clang-format: formalize some of the spacing rulesKarthik Nayak, Jul 13, 2024
  76. 6/8 ci: run style check on GitHub and GitLabKarthik Nayak, Jul 13, 2024
  77. Junio C HamanoJul 13, 2024
  78. 7/8 check-whitespace: detect if no base_commit is providedKarthik Nayak, Jul 13, 2024
  79. 8/8 ci/style-check: add `RemoveBracesLLVM` to '.clang-format'Karthik Nayak, Jul 13, 2024
  80. Junio C HamanoJul 13, 2024
  81. Karthik NayakJul 13, 2024
  82. Ramsay JonesJul 13, 2024
  83. Karthik NayakJul 15, 2024
  84. Junio C HamanoJul 15, 2024
  85. Karthik NayakJul 15, 2024
  86. Junio C HamanoJul 15, 2024
  87. Karthik NayakJul 15, 2024
  88. Junio C HamanoJul 15, 2024
  89. Karthik NayakJul 18, 2024
  90. Junio C HamanoJul 18, 2024
  91. 0/8 clang-format: add more rules and enable on CIKarthik Nayak, Jul 15, 2024
  92. 1/8 clang-format: indent preprocessor directives after hashKarthik Nayak, Jul 15, 2024
  93. 2/8 clang-format: avoid spacing around bitfield colonKarthik Nayak, Jul 15, 2024
  94. 3/8 clang-format: ensure files end with newlinesKarthik Nayak, Jul 15, 2024
  95. 4/8 clang-format: replace deprecated option with 'SpacesInParens'Karthik Nayak, Jul 15, 2024
  96. 5/8 clang-format: formalize some of the spacing rulesKarthik Nayak, Jul 15, 2024
  97. 6/8 ci: run style check on GitHub and GitLabKarthik Nayak, Jul 15, 2024
  98. 7/8 check-whitespace: detect if no base_commit is providedKarthik Nayak, Jul 15, 2024
  99. 8/8 ci/style-check: add `RemoveBracesLLVM` to '.clang-format'Karthik Nayak, Jul 15, 2024
  100. Junio C HamanoJul 15, 2024
  101. Karthik NayakJul 15, 2024
  102. 0/6 : add more rules and enable on CIKarthik Nayak, Jul 18, 2024
  103. 1/6 clang-format: indent preprocessor directives after hashKarthik Nayak, Jul 18, 2024
  104. 2/6 clang-format: avoid spacing around bitfield colonKarthik Nayak, Jul 18, 2024
  105. 3/6 clang-format: formalize some of the spacing rulesKarthik Nayak, Jul 18, 2024
  106. 4/6 ci: run style check on GitHub and GitLabKarthik Nayak, Jul 18, 2024
  107. Junio C HamanoJul 18, 2024
  108. Junio C HamanoJul 18, 2024
  109. 5/6 check-whitespace: detect if no base_commit is providedKarthik Nayak, Jul 18, 2024
  110. Junio C HamanoJul 18, 2024
  111. Karthik NayakJul 19, 2024
  112. Junio C HamanoJul 19, 2024
  113. Karthik NayakJul 22, 2024
  114. 6/6 ci/style-check: add `RemoveBracesLLVM` in CI jobKarthik Nayak, Jul 18, 2024
  115. Junio C HamanoJul 18, 2024
  116. 0/6 clang-format: add more rules and enable on CIKarthik Nayak, Jul 23, 2024
  117. 1/6 clang-format: indent preprocessor directives after hashKarthik Nayak, Jul 23, 2024
  118. Patrick SteinhardtJul 24, 2024
  119. Karthik NayakJul 24, 2024
  120. 2/6 clang-format: avoid spacing around bitfield colonKarthik Nayak, Jul 23, 2024
  121. 3/6 clang-format: formalize some of the spacing rulesKarthik Nayak, Jul 23, 2024
  122. 4/6 ci: run style check on GitHub and GitLabKarthik Nayak, Jul 23, 2024
  123. 5/6 check-whitespace: detect if no base_commit is providedKarthik Nayak, Jul 23, 2024
  124. 6/6 ci/style-check: add `RemoveBracesLLVM` in CI jobKarthik Nayak, Jul 23, 2024
  125. Junio C HamanoJun 19, 2025
  126. Karthik NayakJun 19, 2025
  127. Junio C HamanoJun 20, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.