public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aleksander Alekseev <[email protected]>
To: PostgreSQL Hackers <[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, 23 Jun 2025 13:42:32 +0300
Message-ID: <CAJ7c6TOGdVBK5P-s59c77qxaw=ydPjpzp_s3VbpHeHn3Gc1iyA@mail.gmail.com> (raw)
In-Reply-To: <CAE7r3M+phC+kyJsUrJ6z97-UA0LXRrUBJ61hBk7WhRqdXF_itQ@mail.gmail.com>
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>

Hi Arseniy,

Thanks for the feedback!

> Now it affects 4 times more files (380). What I noticed:
> 1) Most of the comments are bordered comments like this:
> -/* --------------------------------------------------------------------------------
> +/*
> + * --------------------------------------------------------------------------------
>   * Public IO related functions operating on IO Handles
>   * --------------------------------------------------------------------------------
>   */
>
> Do we want to skip such comments?
> I have also seen comments with '====' border.

Personally I don't have a strong opinion on this. We can easily add an
exception for "/* ---" and "/* ===" comments if somebody believes this
is a problem. I choose not to add such an exception just yet only
because I don't like unnecessary exceptions :)

> 2) Some comments like this:
>
> before:
> /* Author: Linus Tolke
>    (actually most if the code is "borrowed" from the distribution and just
>    slightly modified)
>  */
>
> after:
> /*
>  * Author: Linus Tolke
>    (actually most if the code is "borrowed" from the distribution and just
>    slightly modified)
>  */
>
> I guess closing */ on the separate line is the trigger?
> If I'm not wrong there are only 3 such comments, maybe it is easier to
> fix them by hand?)
>
> 3) It seems all geqo related file contains such comment:
> -/* contributed by:
> +/*
> + * contributed by:
>     =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
>     *  Martin Utesch                             * Institute of
> Automatic Control          *

You are right, these comments shouldn't have been changed. Apparently
the script is going to need slightly more complicated checks that I
initially thought.

Here is the corrected patch v4.

-- 
Best regards,
Aleksander Alekseev


Attachments:

  [application/octet-stream] v4-0001-pgindent-improve-formatting-of-multiline-comments.patch (2.0K, 2-v4-0001-pgindent-improve-formatting-of-multiline-comments.patch)
  download | inline diff:
From 125c239d704fd755039b2de27e847fcd4dee2406 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email protected]>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v4] 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
Reported-by: Michael Paquier
Reviewed-by: Arseniy Mukhin
Discussion: https://postgr.es/m/CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s%2B_V4%3Dt%2BxgSnZm1cFw%40mail.gmail.com
---
 src/tools/pgindent/pgindent | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index b7d71808924..f009d4ba984 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,32 @@ 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 fist and the last one
+    for my $i ( 1 .. scalar @lines - 2 )
+    {
+        $lines[$i] = " *".$lines[$i] if $lines[$i] !~ /^ \*/;
+    }
+
+    $lines[0] =~ s!/\*(.+)!/\*\n *$1!;
+    $lines[-1] =~ s!(.+) \*/!$1\n \*/!;
+
+    $source = join "\n", @lines;
+
+    return $source;
+}
+
 sub run_indent
 {
 	my $source = shift;
-- 
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], [email protected], [email protected]
  Subject: Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  In-Reply-To: <CAJ7c6TOGdVBK5P-s59c77qxaw=ydPjpzp_s3VbpHeHn3Gc1iyA@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