v1-0001-pg_bsd_indent-improve-formatting-of-multiline-com.patch
application/octet-stream
Filename: v1-0001-pg_bsd_indent-improve-formatting-of-multiline-com.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v1-0001
Subject: pg_bsd_indent: improve formatting of multiline comments
| File | + | − |
|---|---|---|
| src/tools/pg_bsd_indent/indent.c | 35 | 0 |
From e21579b607828a418139183396722ca67fa986ba Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@timescale.com>
Date: Thu, 19 Jun 2025 17:35:20 +0300
Subject: [PATCH v1] pg_bsd_indent: improve formatting of multiline comments
Format multiline comments like this:
/* line 1
* line 2
*/
... into:
/*
* line 1
* line 2
*/
This is more consistent with what we currently have in the tree.
Aleksander Alekseev. Reported by Michael Paquier.
Discussion: TODO FIXME
---
src/tools/pg_bsd_indent/indent.c | 35 ++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/tools/pg_bsd_indent/indent.c b/src/tools/pg_bsd_indent/indent.c
index 2622cc6227a..207f657baab 100644
--- a/src/tools/pg_bsd_indent/indent.c
+++ b/src/tools/pg_bsd_indent/indent.c
@@ -1184,6 +1184,41 @@ check_type:
* character will cause the line to be printed */
case comment: /* we have gotten a / followed by * this is a biggie */
+ /*
+ * Force line break for column-1 multiline comments by inserting
+ * a newline into the buffer right after slash-star. This makes pr_comment()
+ * treat it as a block comment that should be formatted with line breaks.
+ * Ignore "*****" and "-----" comments.
+ */
+ if (ps.col_1 && *buf_ptr != '\n' && *buf_ptr != '-' && *buf_ptr != '*') {
+ char *t_ptr;
+ bool is_single_line = false;
+
+ /* Check if comment end star-slash appears on the same line */
+ t_ptr = buf_ptr;
+ while (*t_ptr != '\0' && *t_ptr != '\n') {
+ if (t_ptr >= buf_end)
+ fill_buffer();
+ if (t_ptr[0] == '*' && t_ptr[1] == '/') {
+ is_single_line = true;
+ break;
+ }
+ t_ptr++;
+ }
+
+ /* Only transform if it's NOT a single-line comment */
+ if (!is_single_line) {
+ /* Insert newline and star right after slash-star by shifting buffer content */
+ if (buf_end < in_buffer_limit - 3) {
+ /* Make room for newline + space + star */
+ memmove(buf_ptr + 3, buf_ptr, buf_end - buf_ptr);
+ *buf_ptr = '\n';
+ *(buf_ptr + 1) = ' ';
+ *(buf_ptr + 2) = '*';
+ buf_end += 3;
+ }
+ }
+ }
pr_comment();
break;
} /* end of big switch stmt */
--
2.49.0