public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aleksander Alekseev <[email protected]>
To: Tom Lane <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Cc: Nathan Bossart <[email protected]>
Subject: Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
Date: Tue, 5 May 2026 16:06:21 +0300
Message-ID: <CAJ7c6TNVeFYAYFs0KDEVsZNPaZtKtHHq+1Mw7=pTw5Hr3g7KGA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[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>
	<aP-H6kSsGOxaB21k@nathan>
	<[email protected]>
	<[email protected]>
	<aTs7A4lbcm0ThXaO@nathan>
	<aYZqyoNlah_E-Zua@nathan>
	<CAJ7c6TPJVau3Ppih7+KubRwvG9CRpXq16L3X9bE02KuGgL95Nw@mail.gmail.com>
	<[email protected]>

Hi Tom,

Thanks for your feedback.

> In this case the problem is that the cleanup pattern only accounts for
> one trailing space.  But a variant of this, which I think affects many
> of the steps in the patch, is that there could be tab(s) there.  You
> should fix the patterns to allow any number of spaces/tabs at the
> spots where they currently expect just one space.  This might result
> in finding cleanups they miss now.

Fair point. Fixed.

> Another amusing diff I noticed:
>
> [...]
>
> Clearly, this is somebody's off-by-one-key typo, and the correct
> fix is s/&/*/.  I suspect that fixing that manually is the most
> expedient answer, rather than trying to make pg_bsd_indent smart
> enough to DTRT.

Agree.

> One other nitpick is that the patch itself needs to be run through
> pgperltidy (which has different opinions than your editor about
> tabs vs spaces, apparently).

Fixed in v7.

-- 
Best regards,
Aleksander Alekseev


Attachments:

  [text/x-patch] v7-0001-pgindent-improve-formatting-of-multiline-comments.patch (2.3K, 2-v7-0001-pgindent-improve-formatting-of-multiline-comments.patch)
  download | inline diff:
From 7c3abf671bafaf3a5425994e9cfedf5dafaf9895 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email protected]>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v7] 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]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s%2B_V4%3Dt%2BxgSnZm1cFw%40mail.gmail.com
---
 src/tools/pgindent/pgindent | 40 +++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index b2ec5e2914b..f4be74fc3a4 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -285,6 +285,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
@@ -293,6 +296,43 @@ 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!^\s+\*!))
+	{
+		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] !~ /^\s+\*/;
+	}
+
+	# Keep /* === and /* --- lines as is
+	if ($lines[0] !~ m!^/\*\s+[=-]+!)
+	{
+		$lines[0] =~ s!/\*(.+)!/\*\n *$1!;
+	}
+
+	# Keep === */ and --- */ lines as is
+	if ($lines[-1] !~ m![=-]+\s+\*/$!)
+	{
+		# also remove trailing whitespaces
+		$lines[-1] =~ s!(.+?)\s+\*/!$1\n \*/!;
+	}
+
+	$source = join "\n", @lines;
+
+	return $source;
+}
+
 sub run_indent
 {
 	my $source = shift;
-- 
2.43.0



view thread (4+ messages)

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]
  Subject: Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  In-Reply-To: <CAJ7c6TNVeFYAYFs0KDEVsZNPaZtKtHHq+1Mw7=pTw5Hr3g7KGA@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