diff mbox series

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

Message ID xmqqa5irkfw3.fsf_-_@gitster.g (mailing list archive)
State New, archived
Headers show
Series Re* [PATCH 1/8] clang-format: indent preprocessor directives after hash | expand

Commit Message

Junio C Hamano July 8, 2024, 4:27 p.m. UTC
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 mbox series

Patch

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