public inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH] pg_bsd_indent: improve formatting of multiline comments
26+ messages / 9 participants
[nested] [flat]

* [PATCH] pg_bsd_indent: improve formatting of multiline comments
@ 2025-06-19 14:51 Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Aleksander Alekseev @ 2025-06-19 14:51 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Michael Paquier <[email protected]>

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



^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-06-19 20:33 ` Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Arseniy Mukhin @ 2025-06-19 20:33 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Michael Paquier <[email protected]>

On Thu, Jun 19, 2025 at 5:51 PM Aleksander Alekseev
<[email protected]> wrote:
>
> 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

Hi Aleksander!

Thank you for the patch!

I tried it with the whole project and almost always it works great.
But I noticed two cases where it works probably not as expected:

1) comments which don't have a star on each line. For example:
file 'cube.c'

before:
/* make up a metric in which one box will be 'lower' than the other
   -- this can be useful for sorting and to determine uniqueness */

after:
/*
 * make up a metric in which one box will be 'lower' than the other
   -- this can be useful for sorting and to determine uniqueness */

2) comments where closing */ is on the last comment line. For example:
file 'crypt-blowfish.c'

before:
/* This has to be bug-compatible with the original implementation, so
 * only encode 23 of the 24 bytes. :-) */

after:
/*
 * This has to be bug-compatible with the original implementation, so
 * only encode 23 of the 24 bytes. :-) */


Best regards,
Arseniy Mukhin





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
@ 2025-06-20 13:44   ` Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Aleksander Alekseev @ 2025-06-20 13:44 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Arseniy Mukhin <[email protected]>; Michael Paquier <[email protected]>

Hi Arseniy,

> I tried it with the whole project and almost always it works great.
> But I noticed two cases where it works probably not as expected:
>
> 1) comments which don't have a star on each line. For example:
> file 'cube.c'
>
> before:
> /* make up a metric in which one box will be 'lower' than the other
>    -- this can be useful for sorting and to determine uniqueness */
>
> after:
> /*
>  * make up a metric in which one box will be 'lower' than the other
>    -- this can be useful for sorting and to determine uniqueness */
>
> 2) comments where closing */ is on the last comment line. For example:
> file 'crypt-blowfish.c'
>
> before:
> /* This has to be bug-compatible with the original implementation, so
>  * only encode 23 of the 24 bytes. :-) */
>
> after:
> /*
>  * This has to be bug-compatible with the original implementation, so
>  * only encode 23 of the 24 bytes. :-) */

Thanks for the review. You are right, these comments shouldn't be affected.

It's going to be simpler to modify pgindent then. PFA the updated patch.

-- 
Best regards,
Aleksander Alekseev


Attachments:

  [application/octet-stream] v2-0001-pgindent-improve-formatting-of-multiline-comments.patch (1.9K, 2-v2-0001-pgindent-improve-formatting-of-multiline-comments.patch)
  download | inline diff:
From 66d585409a93ca5fba9035cc9e939424d9206ad9 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email protected]>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v2] 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 | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index b7d71808924..49cb917cc5d 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
+	$source =~ s!^(/\*.*?\*/)!postprocess_multiline_comment($1)!mgse;
+
 	## Functions
 
 	# Use a single space before '*' in function return types
@@ -289,6 +292,37 @@ sub post_indent
 	return $source;
 }
 
+sub postprocess_multiline_comment
+{
+    my $source = shift;
+    my @lines = split "\n", $source;
+
+    if($lines[0] ne "/*" && $lines[-1] ne " */")
+    {
+        # Don't change comments like:
+        # /* line 1
+        #    line 2 */
+        # and similar.
+        return $source;
+    }
+
+    if($lines[0] =~ m!/\*(\-|\*)!)
+    {
+        # Don't change comments that start with:
+        # /****
+        # or:
+        # /*---
+        return $source;
+    }
+
+    $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



^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-06-20 13:56     ` Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Bruce Momjian @ 2025-06-20 13:56 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Arseniy Mukhin <[email protected]>; Michael Paquier <[email protected]>

On Fri, Jun 20, 2025 at 04:44:08PM +0300, Aleksander Alekseev wrote:
> Hi Arseniy,
> 
> > I tried it with the whole project and almost always it works great.
> > But I noticed two cases where it works probably not as expected:
> >
> > 1) comments which don't have a star on each line. For example:
> > file 'cube.c'
> >
> > before:
> > /* make up a metric in which one box will be 'lower' than the other
> >    -- this can be useful for sorting and to determine uniqueness */
> >
> > after:
> > /*
> >  * make up a metric in which one box will be 'lower' than the other
> >    -- this can be useful for sorting and to determine uniqueness */
> >
> > 2) comments where closing */ is on the last comment line. For example:
> > file 'crypt-blowfish.c'
> >
> > before:
> > /* This has to be bug-compatible with the original implementation, so
> >  * only encode 23 of the 24 bytes. :-) */
> >
> > after:
> > /*
> >  * This has to be bug-compatible with the original implementation, so
> >  * only encode 23 of the 24 bytes. :-) */
> 
> Thanks for the review. You are right, these comments shouldn't be affected.
> 
> It's going to be simpler to modify pgindent then. PFA the updated patch.

Given the quality of BSD indent code, I have _always_ found it easier to
modify pgindent.  ;-

-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Do not let urgent matters crowd out time for investment in the future.





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
@ 2025-06-20 14:01       ` Aleksander Alekseev <[email protected]>
  2025-06-20 14:14         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  0 siblings, 2 replies; 26+ messages in thread

From: Aleksander Alekseev @ 2025-06-20 14:01 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Bruce Momjian <[email protected]>; Arseniy Mukhin <[email protected]>; Michael Paquier <[email protected]>

Hi,

> Given the quality of BSD indent code, I have _always_ found it easier to
> modify pgindent.  ;-

:D Initially I thought that the problem was simple enough to solve it
in C, but this turned out not to be true.

> It's going to be simpler to modify pgindent then. PFA the updated patch.

I noticed a mistake in v2. Here is the corrected patch. Changes
comparing to the previous version:

```
-    $lines[-1] =~ s!/(.+)\*/!/$1\n \*/!;
+    $lines[-1] =~ s!(.+) \*/!$1\n \*/!;
```

-- 
Best regards,
Aleksander Alekseev


Attachments:

  [application/octet-stream] v3-0001-pgindent-improve-formatting-of-multiline-comments.patch (1.9K, 2-v3-0001-pgindent-improve-formatting-of-multiline-comments.patch)
  download | inline diff:
From 97bfd645a9313b8892d64fc9acc063d9e982e9d7 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email protected]>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v3] 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 | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index b7d71808924..13944730a39 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
+	$source =~ s!^(/\*.*?\*/)!postprocess_multiline_comment($1)!mgse;
+
 	## Functions
 
 	# Use a single space before '*' in function return types
@@ -289,6 +292,37 @@ sub post_indent
 	return $source;
 }
 
+sub postprocess_multiline_comment
+{
+    my $source = shift;
+    my @lines = split "\n", $source;
+
+    if($lines[0] ne "/*" && $lines[-1] ne " */")
+    {
+        # Don't change comments like:
+        # /* line 1
+        #    line 2 */
+        # and similar.
+        return $source;
+    }
+
+    if($lines[0] =~ m!/\*(\-|\*)!)
+    {
+        # Don't change comments that start with:
+        # /****
+        # or:
+        # /*---
+        return $source;
+    }
+
+    $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



^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-06-20 14:14         ` Bruce Momjian <[email protected]>
  1 sibling, 0 replies; 26+ messages in thread

From: Bruce Momjian @ 2025-06-20 14:14 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Arseniy Mukhin <[email protected]>; Michael Paquier <[email protected]>

On Fri, Jun 20, 2025 at 05:01:41PM +0300, Aleksander Alekseev wrote:
> Hi,
> 
> > Given the quality of BSD indent code, I have _always_ found it easier to
> > modify pgindent.  ;-
> 
> :D Initially I thought that the problem was simple enough to solve it
> in C, but this turned out not to be true.

I always found it ironic that a tool designed to make source code easier
to understand like BSD indent is so hard to understand.  Its use of
short variable names alone is confusing.

-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Do not let urgent matters crowd out time for investment in the future.





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-06-21 18:54         ` Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  1 sibling, 1 reply; 26+ messages in thread

From: Arseniy Mukhin @ 2025-06-21 18:54 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

On Fri, Jun 20, 2025 at 5:01 PM Aleksander Alekseev
<[email protected]> wrote:
>
> Hi,
>
> > Given the quality of BSD indent code, I have _always_ found it easier to
> > modify pgindent.  ;-
>
> :D Initially I thought that the problem was simple enough to solve it
> in C, but this turned out not to be true.
>
> > It's going to be simpler to modify pgindent then. PFA the updated patch.
>
> I noticed a mistake in v2. Here is the corrected patch. Changes
> comparing to the previous version:
>

Thanks!

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.

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          *
    =


Best regards,
Arseniy Mukhin





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
@ 2025-06-23 10:42           ` Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Aleksander Alekseev @ 2025-06-23 10:42 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

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



^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-10-23 20:25             ` Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Nathan Bossart @ 2025-10-23 20:25 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

On Mon, Jun 23, 2025 at 01:42:32PM +0300, Aleksander Alekseev wrote:
>> 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 :)

+1 for adding an exception for "/* -----" style comments.  I tested running
pgindent after applying the patch, and the first thing I noticed was all
these (IMHO) unnecessary changes.  I don't think it helps readability, and
even if it did, it's arguably not worth the churn.

-- 
nathan





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
@ 2025-10-27 12:13               ` Aleksander Alekseev <[email protected]>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  0 siblings, 2 replies; 26+ messages in thread

From: Aleksander Alekseev @ 2025-10-27 12:13 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

Hi Nathan,

> > 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 :)
>
> +1 for adding an exception for "/* -----" style comments.  I tested running
> pgindent after applying the patch, and the first thing I noticed was all
> these (IMHO) unnecessary changes.  I don't think it helps readability, and
> even if it did, it's arguably not worth the churn.

OK, here is the corrected patch v5.

-- 
Best regards,
Aleksander Alekseev


Attachments:

  [text/x-patch] v5-0001-pgindent-improve-formatting-of-multiline-comments.patch (2.3K, 2-v5-0001-pgindent-improve-formatting-of-multiline-comments.patch)
  download | inline diff:
From f87137673c0b3da5aed296f88016e8d8edfd3915 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email protected]>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v5] 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..670e204e917 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 fist 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



^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-10-27 14:55                 ` Nathan Bossart <[email protected]>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <[email protected]>
  1 sibling, 1 reply; 26+ messages in thread

From: Nathan Bossart @ 2025-10-27 14:55 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

On Mon, Oct 27, 2025 at 03:13:33PM +0300, Aleksander Alekseev wrote:
> OK, here is the corrected patch v5.

Thanks.  I had to run pgindent twice before it stopped making changes, but
the results look pretty good to me.  However, I still noticed a few
oddities.

--- a/contrib/seg/seg.c
+++ b/contrib/seg/seg.c
@@ -2,9 +2,9 @@
  * contrib/seg/seg.c
  *
  ******************************************************************************
-  This file contains routines that can be bound to a Postgres backend and
-  called by the backend in the process of processing queries.  The calling
-  format for these routines is dictated by Postgres architecture.
+ *  This file contains routines that can be bound to a Postgres backend and
+ *  called by the backend in the process of processing queries.  The calling
+ *  format for these routines is dictated by Postgres architecture.
 ******************************************************************************/

This one is a little weird, but maybe it's okay...  It looks like pgindent
retains the spacing (or lack of spacing) in this situation.  It's probably
not worth the complexity to try to make it smarter here.

--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -69,7 +69,7 @@
 /*
  * DISABLE_LEADER_PARTICIPATION disables the leader's participation in
  * parallel index builds.  This may be useful as a debugging aid.
-#undef DISABLE_LEADER_PARTICIPATION
+ *#undef DISABLE_LEADER_PARTICIPATION
  */

IMHO we should either remove this line or move it out of the comment.
AFAICT we ordinarily don't #undef debugging stuff like this, presumably so
you can change it with compile flags.

In aclcheck.c and analyze.c, The **** and ==== lines are still getting
bumped down to a new line.

-.* This function just encapsulates the framing rules.
+ *.* This function just encapsulates the framing rules.

This looks like a goof in commit 25a30bb.  I'll go fix that one separately.

--- a/src/backend/storage/ipc/waiteventset.c
+++ b/src/backend/storage/ipc/waiteventset.c
@@ -2010,7 +2010,7 @@ ResOwnerReleaseWaitEventSet(Datum res)
  * NB: be sure to save and restore errno around it.  (That's standard practice
  * in most signal handlers, of course, but we used to omit it in handlers that
  * only set a flag.) XXX
-  *
+ *  *

This one looks like a goof in commit 393e0d2.  It's interesting that
pgindent chooses to add an extra * here, though.

-- 
nathan





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
@ 2025-10-27 23:35                   ` Michael Paquier <[email protected]>
  2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Michael Paquier @ 2025-10-27 23:35 UTC (permalink / raw)
  To: Nathan Bossart <[email protected]>; +Cc: Aleksander Alekseev <[email protected]>; PostgreSQL Hackers <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>

On Mon, Oct 27, 2025 at 09:55:38AM -0500, Nathan Bossart wrote:
>  /*
>   * DISABLE_LEADER_PARTICIPATION disables the leader's participation in
>   * parallel index builds.  This may be useful as a debugging aid.
> -#undef DISABLE_LEADER_PARTICIPATION
> + *#undef DISABLE_LEADER_PARTICIPATION
>   */
> 
> IMHO we should either remove this line or move it out of the comment.
> AFAICT we ordinarily don't #undef debugging stuff like this, presumably so
> you can change it with compile flags.

I would put this one on a separate line, outside the comment.  It's
minor, still we use this style in pg_config_manual.h.  See around
REALLOCATE_BITMAPSETS.
--
Michael


Attachments:

  [application/pgp-signature] signature.asc (833B, 2-signature.asc)
  download

^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <[email protected]>
@ 2025-10-28 00:36                     ` Chao Li <[email protected]>
  2025-12-11 21:43                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Chao Li @ 2025-10-28 00:36 UTC (permalink / raw)
  To: Michael Paquier <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Aleksander Alekseev <[email protected]>; PostgreSQL Hackers <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>



> On Oct 28, 2025, at 07:35, Michael Paquier <[email protected]> wrote:
> 
> On Mon, Oct 27, 2025 at 09:55:38AM -0500, Nathan Bossart wrote:
>> /*
>>  * DISABLE_LEADER_PARTICIPATION disables the leader's participation in
>>  * parallel index builds.  This may be useful as a debugging aid.
>> -#undef DISABLE_LEADER_PARTICIPATION
>> + *#undef DISABLE_LEADER_PARTICIPATION
>>  */
>> 
>> IMHO we should either remove this line or move it out of the comment.
>> AFAICT we ordinarily don't #undef debugging stuff like this, presumably so
>> you can change it with compile flags.
> 
> I would put this one on a separate line, outside the comment.  It's
> minor, still we use this style in pg_config_manual.h.  See around
> REALLOCATE_BITMAPSETS.
> --
> Michael

+1

--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <[email protected]>
  2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
@ 2025-12-11 21:43                       ` Nathan Bossart <[email protected]>
  0 siblings, 0 replies; 26+ messages in thread

From: Nathan Bossart @ 2025-12-11 21:43 UTC (permalink / raw)
  To: Chao Li <[email protected]>; +Cc: Michael Paquier <[email protected]>; Aleksander Alekseev <[email protected]>; PostgreSQL Hackers <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>

On Tue, Oct 28, 2025 at 08:36:33AM +0800, Chao Li wrote:
> On Oct 28, 2025, at 07:35, Michael Paquier <[email protected]> wrote:
>> On Mon, Oct 27, 2025 at 09:55:38AM -0500, Nathan Bossart wrote:
>>> /*
>>>  * DISABLE_LEADER_PARTICIPATION disables the leader's participation in
>>>  * parallel index builds.  This may be useful as a debugging aid.
>>> -#undef DISABLE_LEADER_PARTICIPATION
>>> + *#undef DISABLE_LEADER_PARTICIPATION
>>>  */
>>> 
>>> IMHO we should either remove this line or move it out of the comment.
>>> AFAICT we ordinarily don't #undef debugging stuff like this, presumably so
>>> you can change it with compile flags.
>> 
>> I would put this one on a separate line, outside the comment.  It's
>> minor, still we use this style in pg_config_manual.h.  See around
>> REALLOCATE_BITMAPSETS.
> 
> +1

Here's a patch for this.  I also changed the #undefs to #defines.

-- 
nathan


^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-10-28 00:57                 ` Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  1 sibling, 1 reply; 26+ messages in thread

From: Chao Li @ 2025-10-28 00:57 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Nathan Bossart <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>



> On Oct 27, 2025, at 20:13, Aleksander Alekseev <[email protected]> wrote:
> 
> Hi Nathan,
> 
>>> 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 :)
>> 
>> +1 for adding an exception for "/* -----" style comments.  I tested running
>> pgindent after applying the patch, and the first thing I noticed was all
>> these (IMHO) unnecessary changes.  I don't think it helps readability, and
>> even if it did, it's arguably not worth the churn.
> 
> OK, here is the corrected patch v5.
> 
> -- 
> Best regards,
> Aleksander Alekseev
> <v5-0001-pgindent-improve-formatting-of-multiline-comments.patch>

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 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
```

fist => first

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.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
@ 2025-11-10 09:28                   ` Aleksander Alekseev <[email protected]>
  2025-11-11 06:28                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  0 siblings, 2 replies; 26+ messages in thread

From: Aleksander Alekseev @ 2025-11-10 09:28 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Chao Li <[email protected]>; Nathan Bossart <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[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



^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-11-11 06:28                     ` Chao Li <[email protected]>
  1 sibling, 0 replies; 26+ messages in thread

From: Chao Li @ 2025-11-11 06:28 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Nathan Bossart <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>



> On Nov 10, 2025, at 17:28, Aleksander Alekseev <[email protected]> wrote:
> 
>> 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.

I recalled that. I ran pgindent on a file from a patch I was reviewing, so, the file was not pgindent-ed yet at the time.

I just tried to run the patched pgindent on several files and no diff generated. So this comment is resolved.

Regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-12-11 21:48                     ` Nathan Bossart <[email protected]>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  1 sibling, 1 reply; 26+ messages in thread

From: Nathan Bossart @ 2025-12-11 21:48 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Chao Li <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

With the latest patch applied, I'm still seeing problems with **** and ====
lines in aclcheck.c and analyze.c, as mentioned upthread [0].  I think we
should also figure out what we want to do for things like this:

  ******************************************************************************
-  This file contains routines that can be bound to a Postgres backend and
-  called by the backend in the process of processing queries.  The calling
-  format for these routines is dictated by Postgres architecture.
+ *  This file contains routines that can be bound to a Postgres backend and
+ *  called by the backend in the process of processing queries.  The calling
+ *  format for these routines is dictated by Postgres architecture.
 ******************************************************************************/

Could we modify the patch to leave these kinds of comments alone?

[0] https://postgr.es/m/aP-H6kSsGOxaB21k%40nathan

-- 
nathan





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
@ 2025-12-12 11:32                       ` Aleksander Alekseev <[email protected]>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Aleksander Alekseev @ 2025-12-12 11:32 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Chao Li <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

Hi Nathan,

> [...]
> I think we should also figure out what we want to do for things like this:
>
>   ******************************************************************************
> -  This file contains routines that can be bound to a Postgres backend and
> -  called by the backend in the process of processing queries.  The calling
> -  format for these routines is dictated by Postgres architecture.
> + *  This file contains routines that can be bound to a Postgres backend and
> + *  called by the backend in the process of processing queries.  The calling
> + *  format for these routines is dictated by Postgres architecture.
>  ******************************************************************************/
>
> Could we modify the patch to leave these kinds of comments alone?

I see 3 files that have this comment:

- src/tutorial/complex.c
- contrib/seg/seg.c
- contrib/cube/cube.c

Note that cube.c is not affected by the new version of pgindent,
because the comment starts with `/****`. Such comments are kept as is.

seg.c and cube.c use a mixed format. The comments start with `/*`
followed by ` *` lines but several lines below don't have ` *` in the
beginning. I don't instantly see a way to process this situation in
pgindent. We can either let it modify these comments, or alternatively
change the first lines of the comments from `/*` to `/**`.

-- 
Best regards,
Aleksander Alekseev





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
@ 2025-12-12 15:53                         ` Álvaro Herrera <[email protected]>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Álvaro Herrera @ 2025-12-12 15:53 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Nathan Bossart <[email protected]>; Chao Li <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

It's strange to see this thread go on about messing with the Perl script
because we're too afraid of pg_bsd_indent.  Maybe we should take
ownership of that code -- improve its own indentation to our
conventions, add comments, rename unclear variables, and so on until we
have something we can work with, and fix these weird bugs and
idiosincratic behaviors we don't like.  I just found out this code dates
back from 1976.

We have a _huge_ regression test for it: our own source code repository.
It's not like any breakage is going to go unnoticed.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"Cómo ponemos nuestros dedos en la arcilla del otro. Eso es la amistad; jugar
al alfarero y ver qué formas se pueden sacar del otro" (C. Halloway en
La Feria de las Tinieblas, R. Bradbury)





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <[email protected]>
@ 2025-12-12 16:17                           ` Tom Lane <[email protected]>
  2025-12-12 16:23                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-12-19 20:02                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  0 siblings, 2 replies; 26+ messages in thread

From: Tom Lane @ 2025-12-12 16:17 UTC (permalink / raw)
  To: Álvaro Herrera <[email protected]>; +Cc: Aleksander Alekseev <[email protected]>; PostgreSQL Hackers <[email protected]>; Nathan Bossart <[email protected]>; Chao Li <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

=?utf-8?Q?=C3=81lvaro?= Herrera <[email protected]> writes:
> It's strange to see this thread go on about messing with the Perl script
> because we're too afraid of pg_bsd_indent.  Maybe we should take
> ownership of that code -- improve its own indentation to our
> conventions, add comments, rename unclear variables, and so on until we
> have something we can work with, and fix these weird bugs and
> idiosincratic behaviors we don't like.  I just found out this code dates
> back from 1976.

I've worked with that code a little bit, and it's mostly unreadable
spaghetti :-(.  If somebody wants to make an effort to make it not
so awful, that'd be great, but I fear it's a very nontrivial project.

Having said that, we've already basically forked it from the NetBSD
upstream, so there is no reason not to diverge further.

> We have a _huge_ regression test for it: our own source code repository.
> It's not like any breakage is going to go unnoticed.

True.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <[email protected]>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <[email protected]>
@ 2025-12-12 16:23                             ` Nathan Bossart <[email protected]>
  2025-12-12 18:37                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <[email protected]>
  1 sibling, 1 reply; 26+ messages in thread

From: Nathan Bossart @ 2025-12-12 16:23 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Álvaro Herrera <[email protected]>; Aleksander Alekseev <[email protected]>; PostgreSQL Hackers <[email protected]>; Chao Li <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

On Fri, Dec 12, 2025 at 11:17:01AM -0500, Tom Lane wrote:
> =?utf-8?Q?=C3=81lvaro?= Herrera <[email protected]> writes:
>> It's strange to see this thread go on about messing with the Perl script
>> because we're too afraid of pg_bsd_indent.  Maybe we should take
>> ownership of that code -- improve its own indentation to our
>> conventions, add comments, rename unclear variables, and so on until we
>> have something we can work with, and fix these weird bugs and
>> idiosincratic behaviors we don't like.  I just found out this code dates
>> back from 1976.
> 
> I've worked with that code a little bit, and it's mostly unreadable
> spaghetti :-(.  If somebody wants to make an effort to make it not
> so awful, that'd be great, but I fear it's a very nontrivial project.

Yeah, I tried to find a bug in it recently and could do little more than
trial-and-error in the areas that seemed vaguely close (with no success).
I'm generally critical of efforts to rewrite things from scratch, but this
might be a case where it's the better option.

-- 
nathan





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <[email protected]>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <[email protected]>
  2025-12-12 16:23                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
@ 2025-12-12 18:37                               ` Tom Lane <[email protected]>
  2025-12-12 21:47                                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  0 siblings, 1 reply; 26+ messages in thread

From: Tom Lane @ 2025-12-12 18:37 UTC (permalink / raw)
  To: Nathan Bossart <[email protected]>; +Cc: Álvaro Herrera <[email protected]>; Aleksander Alekseev <[email protected]>; PostgreSQL Hackers <[email protected]>; Chao Li <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

Nathan Bossart <[email protected]> writes:
> Yeah, I tried to find a bug in it recently and could do little more than
> trial-and-error in the areas that seemed vaguely close (with no success).
> I'm generally critical of efforts to rewrite things from scratch, but this
> might be a case where it's the better option.

There's something to be said for that approach.  Presumably, a rewrite
could be smaller because we wouldn't need to support all the options
bsd_indent has, just the behavior PG wants.

I wonder whether it'd be possible to get rid of the need for
typedefs.list while at it.  That might be impractical --- IIRC, C
syntax is ambiguous if you don't know which identifiers are typedefs.
Still, I believe there are other indenters that get away without
that knowledge, so maybe the ambiguity isn't fatal for indentation
purposes.

With or without that nice-to-have, it'd be a lot of work with
not all that much payoff, so I'm finding it hard to recommend
that somebody go after this.  But maybe someone will find it
irresistible to scratch that itch.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <[email protected]>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <[email protected]>
  2025-12-12 16:23                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-12-12 18:37                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <[email protected]>
@ 2025-12-12 21:47                                 ` Aleksander Alekseev <[email protected]>
  0 siblings, 0 replies; 26+ messages in thread

From: Aleksander Alekseev @ 2025-12-12 21:47 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Tom Lane <[email protected]>; Nathan Bossart <[email protected]>; Álvaro Herrera <[email protected]>; Chao Li <[email protected]>; Arseniy Mukhin <[email protected]>; Bruce Momjian <[email protected]>; Michael Paquier <[email protected]>

Hi,

> It's strange to see this thread go on about messing with the Perl script
> because we're too afraid of pg_bsd_indent.  Maybe we should take
> ownership of that code -- improve its own indentation to our
> conventions, add comments, rename unclear variables, and so on until we
> have something we can work with, and fix these weird bugs and
> idiosincratic behaviors we don't like.  I just found out this code dates
> back from 1976.

> With or without that nice-to-have, it'd be a lot of work with
> not all that much payoff, so I'm finding it hard to recommend
> that somebody go after this.  But maybe someone will find it
> irresistible to scratch that itch.

I was thinking just recently that rewriting pgindent in Python might
be a good idea for future refactoring, but probably only if and after
we merge PyTest patchset [1]. (Which strangely enough is missing on
the nearest open commitfest.)

[1]: https://www.postgresql.org/message-id/flat/CAOYmi%2BkThkM9Z87u%3DR_Wi7fCor2i%2BUZKAyq0UCyprzCwTQvqgA...
--
Best regards,
Aleksander Alekseev





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <[email protected]>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <[email protected]>
@ 2025-12-19 20:02                             ` Bruce Momjian <[email protected]>
  2025-12-21 22:33                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <[email protected]>
  1 sibling, 1 reply; 26+ messages in thread

From: Bruce Momjian @ 2025-12-19 20:02 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Álvaro Herrera <[email protected]>; Aleksander Alekseev <[email protected]>; PostgreSQL Hackers <[email protected]>; Nathan Bossart <[email protected]>; Chao Li <[email protected]>; Arseniy Mukhin <[email protected]>; Michael Paquier <[email protected]>

On Fri, Dec 12, 2025 at 11:17:01AM -0500, Tom Lane wrote:
> =?utf-8?Q?=C3=81lvaro?= Herrera <[email protected]> writes:
> > It's strange to see this thread go on about messing with the Perl script
> > because we're too afraid of pg_bsd_indent.  Maybe we should take
> > ownership of that code -- improve its own indentation to our
> > conventions, add comments, rename unclear variables, and so on until we
> > have something we can work with, and fix these weird bugs and
> > idiosincratic behaviors we don't like.  I just found out this code dates
> > back from 1976.
> 
> I've worked with that code a little bit, and it's mostly unreadable
> spaghetti :-(.  If somebody wants to make an effort to make it not
> so awful, that'd be great, but I fear it's a very nontrivial project.

Yes, this is why we had to wrap the pg_bsd_indent call in Perl.

-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Do not let urgent matters crowd out time for investment in the future.





^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <[email protected]>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <[email protected]>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <[email protected]>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <[email protected]>
  2025-12-19 20:02                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <[email protected]>
@ 2025-12-21 22:33                               ` Michael Paquier <[email protected]>
  0 siblings, 0 replies; 26+ messages in thread

From: Michael Paquier @ 2025-12-21 22:33 UTC (permalink / raw)
  To: Bruce Momjian <[email protected]>; +Cc: Tom Lane <[email protected]>; Álvaro Herrera <[email protected]>; Aleksander Alekseev <[email protected]>; PostgreSQL Hackers <[email protected]>; Nathan Bossart <[email protected]>; Chao Li <[email protected]>; Arseniy Mukhin <[email protected]>

On Fri, Dec 19, 2025 at 03:02:12PM -0500, Bruce Momjian wrote:
> On Fri, Dec 12, 2025 at 11:17:01AM -0500, Tom Lane wrote:
>> =?utf-8?Q?=C3=81lvaro?= Herrera <[email protected]> writes:
>>> It's strange to see this thread go on about messing with the Perl script
>>> because we're too afraid of pg_bsd_indent.  Maybe we should take
>>> ownership of that code -- improve its own indentation to our
>>> conventions, add comments, rename unclear variables, and so on until we
>>> have something we can work with, and fix these weird bugs and
>>> idiosincratic behaviors we don't like.  I just found out this code dates
>>> back from 1976.
>> 
>> I've worked with that code a little bit, and it's mostly unreadable
>> spaghetti :-(.  If somebody wants to make an effort to make it not
>> so awful, that'd be great, but I fear it's a very nontrivial project.
> 
> Yes, this is why we had to wrap the pg_bsd_indent call in Perl.

Removing one layer, finishing with only a C function or a perl script
would be really nice.  I am wondering if removing the perl script
would not be the way to go, just owning the portion of the code we
care about, which is already in the tree anyway.

From what I can see, we rely on a set of options through $indent_opts,
it seems like one would enter a fail-and-retry repeat loop until
things get rather right: 
- Remove as much code from pg_bsd_indent as possible.
- Integrate some of the options in the perl script into the binary.

If the binary gets slim enough and more understandable, perhaps we
could even keep both, we have all the pgtypedef business which is
specific to the Postgres tree as well.
--
Michael


Attachments:

  [application/pgp-signature] signature.asc (833B, 2-signature.asc)
  download

^ permalink  raw  reply  [nested|flat] 26+ messages in thread


end of thread, other threads:[~2025-12-21 22:33 UTC | newest]

Thread overview: 26+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
2025-06-19 20:33 ` Arseniy Mukhin <[email protected]>
2025-06-20 13:44   ` Aleksander Alekseev <[email protected]>
2025-06-20 13:56     ` Bruce Momjian <[email protected]>
2025-06-20 14:01       ` Aleksander Alekseev <[email protected]>
2025-06-20 14:14         ` Bruce Momjian <[email protected]>
2025-06-21 18:54         ` Arseniy Mukhin <[email protected]>
2025-06-23 10:42           ` Aleksander Alekseev <[email protected]>
2025-10-23 20:25             ` Nathan Bossart <[email protected]>
2025-10-27 12:13               ` Aleksander Alekseev <[email protected]>
2025-10-27 14:55                 ` Nathan Bossart <[email protected]>
2025-10-27 23:35                   ` Michael Paquier <[email protected]>
2025-10-28 00:36                     ` Chao Li <[email protected]>
2025-12-11 21:43                       ` Nathan Bossart <[email protected]>
2025-10-28 00:57                 ` Chao Li <[email protected]>
2025-11-10 09:28                   ` Aleksander Alekseev <[email protected]>
2025-11-11 06:28                     ` Chao Li <[email protected]>
2025-12-11 21:48                     ` Nathan Bossart <[email protected]>
2025-12-12 11:32                       ` Aleksander Alekseev <[email protected]>
2025-12-12 15:53                         ` Álvaro Herrera <[email protected]>
2025-12-12 16:17                           ` Tom Lane <[email protected]>
2025-12-12 16:23                             ` Nathan Bossart <[email protected]>
2025-12-12 18:37                               ` Tom Lane <[email protected]>
2025-12-12 21:47                                 ` Aleksander Alekseev <[email protected]>
2025-12-19 20:02                             ` Bruce Momjian <[email protected]>
2025-12-21 22:33                               ` Michael Paquier <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox