public inbox for [email protected]
help / color / mirror / Atom feedFrom: Aleksander Alekseev <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Cc: Michael Paquier <[email protected]>
Subject: [PATCH] pg_bsd_indent: improve formatting of multiline comments
Date: Thu, 19 Jun 2025 17:51:36 +0300
Message-ID: <CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s+_V4=t+xgSnZm1cFw@mail.gmail.com> (raw)
Hi,
Michael (cc:'ed) pointed out [1] that pg_bsd_indent could do a
slightly better job when it comes to formatting multiline comments. I
prepared a patch that fixes this.
How to test it:
```
ninja -C build
cp build/src/tools/pg_bsd_indent/pg_bsd_indent ~/bin/pg_bsd_indent
cp src/tools/pgindent/pgindent ~/bin/pgindent
pgindent src/backend/utils/adt/varlena.c
git diff
```
Expected changes:
```
-/* name_text()
+/*
+ * name_text()
* Converts a Name type to a text type.
*/
```
Everything else should work as before.
Thoughts and feedback are most welcomed.
[1]: https://postgr.es/m/CAJ7c6TN7ppSmZMPejvKZreOs%3D%2BkJEhrGQNuVpmTjj9W-%3DMjgCg%40mail.gmail.com
--
Best regards,
Aleksander Alekseev
Attachments:
[application/octet-stream] v1-0001-pg_bsd_indent-improve-formatting-of-multiline-com.patch (2.1K, 2-v1-0001-pg_bsd_indent-improve-formatting-of-multiline-com.patch)
download | inline diff:
From e21579b607828a418139183396722ca67fa986ba Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email protected]>
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
view thread (26+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
In-Reply-To: <CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s+_V4=t+xgSnZm1cFw@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox