public inbox for [email protected]
help / color / mirror / Atom feedFrom: Aleksander Alekseev <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Cc: Chao Li <[email protected]>
Cc: Nathan Bossart <[email protected]>
Cc: Arseniy Mukhin <[email protected]>
Cc: Bruce Momjian <[email protected]>
Cc: Michael Paquier <[email protected]>
Subject: Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
Date: Mon, 10 Nov 2025 12:28:06 +0300
Message-ID: <CAJ7c6TPCJz-ExBFL8q2dCkXZpUdpm=+wvTF11gDENGk39n3DYA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s+_V4=t+xgSnZm1cFw@mail.gmail.com>
<CAE7r3MJ=CcWw65=C=tET32z5joixFqMDY_XhCxvjpLcOL3nVAQ@mail.gmail.com>
<CAJ7c6TOp_h5Ueu8tPTnmponG84oFrm3D+zFWBwae-80do6o-rA@mail.gmail.com>
<[email protected]>
<CAJ7c6TOCJG2p0Ob9Z7mXQRhkmRX_mxBay198Z173t4=PZr=yEQ@mail.gmail.com>
<CAE7r3M+phC+kyJsUrJ6z97-UA0LXRrUBJ61hBk7WhRqdXF_itQ@mail.gmail.com>
<CAJ7c6TOGdVBK5P-s59c77qxaw=ydPjpzp_s3VbpHeHn3Gc1iyA@mail.gmail.com>
<aPqPK4ERy5-jj185@nathan>
<CAJ7c6TMTzQsnKfM+_4i-4WO7=YnV4nO8ABWA6enSpdtg6DKhqQ@mail.gmail.com>
<[email protected]>
Hi,
> I am afraid that would generate a lot of noises for future reviews.
>
> 2. A typo in the patch
>
> ```
> + # Check each line except for the fist and the last one
> ```
Thanks, fixed.
> 3. As you are updating pgindent, I want to report an issue, you may address in a separate patch or just in this patch, up to you.
>
> See this code:
> ```
> else
> /*
> * fetch all the rest of the page
> */
> copysize = QUEUE_PAGESIZE - curoffset;
> ```
>
> In the “else” clause, there is a multiple-line comment block, and a single line of code. Pgindent will add an empty line between “else” and the comment block, which is weird. If the comment is one-line, then no empty line will be inserted.
I didn't manage to find this code. The closest thing I see is in
src/backend/commands/async.c:
```
else
{
/* fetch all the rest of the page */
copysize = QUEUE_PAGESIZE - curoffset;
}
```
Last time it was touched 15 years ago and pgindent processes it as expected.
> 1. I just ran the patched pgindent against a random file, then I got a lot diffs like:
>
> ```
> /*
> - * Direct advancement: avoid waking non-caught up backends that
> - * aren't interested in our notifications.
> + * Direct advancement: avoid waking non-caught up backends that aren't
> + * interested in our notifications.
> */
> ```
I'm not sure if this is part of the PostgreSQL code base either. My
best guess is that something is wrong with whitespaces here (tabs vs
spaces). We have plenty of multiline comments like this and from what
I can tell they are processed correctly.
--
Best regards,
Aleksander Alekseev
Attachments:
[text/x-patch] v6-0001-pgindent-improve-formatting-of-multiline-comments.patch (2.3K, 2-v6-0001-pgindent-improve-formatting-of-multiline-comments.patch)
download | inline diff:
From ad91fda8a7406f9fd5dbbfe5a895a811230e2eec Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email protected]>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v6] pgindent: 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.
Author: Aleksander Alekseev <[email protected]>
Reported-by: Michael Paquier <[email protected]>
Reviewed-by: Arseniy Mukhin <[email protected]>
Reviewed-by: Nathan Bossart <[email protected]>
Discussion: https://postgr.es/m/CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s%2B_V4%3Dt%2BxgSnZm1cFw%40mail.gmail.com
---
src/tools/pgindent/pgindent | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index b7d71808924..4db12cb1d92 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -281,6 +281,9 @@ sub post_indent
# Fix run-together comments to have a tab between them
$source =~ s!\*/(/\*.*\*/)$!*/\t$1!gm;
+ # Postprocess multiline comments except for /**... and /*-... ones
+ $source =~ s!^(/\*[^\*\-].*?\*/)!postprocess_multiline_comment($1)!mgse;
+
## Functions
# Use a single space before '*' in function return types
@@ -289,6 +292,39 @@ sub post_indent
return $source;
}
+sub postprocess_multiline_comment
+{
+ my $source = shift;
+ my @lines = split "\n", $source;
+
+ # Only format comments that match the expected format,
+ # or at least that could have been the author's intent.
+ if (($lines[0] ne "/*" && $lines[-1] ne " */") or ($lines[1] !~ m!^ \*!))
+ {
+ return $source;
+ }
+
+ # Check each line except for the first and the last one
+ for my $i ( 1 .. scalar @lines - 2 )
+ {
+ $lines[$i] = " *".$lines[$i] if $lines[$i] !~ /^ \*/;
+ }
+
+ # Keep /* === and /* --- lines as is
+ if ($lines[0] !~ m!^/\* [=-]+!) {
+ $lines[0] =~ s!/\*(.+)!/\*\n *$1!;
+ }
+
+ # Keep === */ and --- */ lines as is
+ if ($lines[-1] !~ m![=-]+ \*/$!) {
+ $lines[-1] =~ s!(.+) \*/!$1\n \*/!;
+ }
+
+ $source = join "\n", @lines;
+
+ return $source;
+}
+
sub run_indent
{
my $source = shift;
--
2.43.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], [email protected], [email protected], [email protected], [email protected]
Subject: Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
In-Reply-To: <CAJ7c6TPCJz-ExBFL8q2dCkXZpUdpm=+wvTF11gDENGk39n3DYA@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