pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH 4/6] TAP test for the slot limit feature
32+ messages / 10 participants
[nested] [flat]

* [PATCH 4/6] TAP test for the slot limit feature
@ 2017-12-21 08:33 Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
  0 siblings, 0 replies; 32+ messages in thread

From: Kyotaro Horiguchi @ 2017-12-21 08:33 UTC (permalink / raw)

---
 src/test/recovery/t/016_replslot_limit.pl | 184 ++++++++++++++++++++++
 1 file changed, 184 insertions(+)
 create mode 100644 src/test/recovery/t/016_replslot_limit.pl

diff --git a/src/test/recovery/t/016_replslot_limit.pl b/src/test/recovery/t/016_replslot_limit.pl
new file mode 100644
index 0000000000..e150ca7a54
--- /dev/null
+++ b/src/test/recovery/t/016_replslot_limit.pl
@@ -0,0 +1,184 @@
+# Test for replication slot limit
+# Ensure that max_slot_wal_keep_size limits the number of WAL files to
+# be kept by replication slots.
+
+use strict;
+use warnings;
+use File::Path qw(rmtree);
+use PostgresNode;
+use TestLib;
+use Test::More tests => 11;
+use Time::HiRes qw(usleep);
+
+$ENV{PGDATABASE} = 'postgres';
+
+# Initialize master node, setting wal-segsize to 1MB
+my $node_master = get_new_node('master');
+$node_master->init(allows_streaming => 1, extra => ['--wal-segsize=1']);
+$node_master->append_conf('postgresql.conf', qq(
+min_wal_size = 2MB
+max_wal_size = 3MB
+));
+$node_master->start;
+$node_master->safe_psql('postgres', "SELECT pg_create_physical_replication_slot('rep1')");
+
+# The slot state should be the state "unknown" before the first connection
+my $result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
+is($result, "|unknown|0", 'check the state of non-reserved slot is "unknown"');
+
+
+# Take backup
+my $backup_name = 'my_backup';
+$node_master->backup($backup_name);
+
+# Create a standby linking to it using the replication slot
+my $node_standby = get_new_node('standby_1');
+$node_standby->init_from_backup($node_master, $backup_name, has_streaming => 1, primary_slot_name => 'rep1');
+
+$node_standby->start;
+
+# Wait until standby has replayed enough data
+my $start_lsn = $node_master->lsn('write');
+$node_master->wait_for_catchup($node_standby, 'replay', $start_lsn);
+
+# Stop standby
+$node_standby->stop;
+
+
+# Preparation done, the slot is the state "streaming" now
+$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
+is($result, "$start_lsn|streaming|0", 'check the catching-up state');
+
+# Advance WAL by five segments (= 5MB) on master
+advance_wal($node_master, 5);
+$node_master->safe_psql('postgres', "CHECKPOINT;");
+
+# The slot is always "safe" when max_slot_wal_keep_size is not set
+$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
+is($result, "$start_lsn|streaming|0", 'check that slot is working');
+
+# The standby can connect to master
+$node_standby->start;
+
+$start_lsn = $node_master->lsn('write');
+$node_master->wait_for_catchup($node_standby, 'replay', $start_lsn);
+
+$node_standby->stop;
+
+# Set max_slot_wal_keep_size on master
+my $max_slot_wal_keep_size_mb = 3;
+$node_master->append_conf('postgresql.conf', qq(
+max_slot_wal_keep_size = ${max_slot_wal_keep_size_mb}MB
+));
+$node_master->reload;
+
+# The slot is in safe state. The remaining bytes should be as almost
+# (max_slot_wal_keep_size + 1) times large as the segment size
+$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, pg_size_pretty(remain) as remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
+is($result, "$start_lsn|streaming|4096 kB", 'check that max_slot_wal_keep_size is working');
+
+# Advance WAL again then checkpoint
+advance_wal($node_master, 2);
+$node_master->safe_psql('postgres', "CHECKPOINT;");
+
+# The slot is still working.
+$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, pg_size_pretty(remain) as remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
+is($result, "$start_lsn|streaming|2048 kB", 'check that remaining byte is calculated correctly');
+
+# wal_keep_segments overrides max_slot_wal_keep_size
+$result = $node_master->safe_psql('postgres', "ALTER SYSTEM SET wal_keep_segments to 6; SELECT pg_reload_conf();");
+$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, pg_size_pretty(remain) as remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
+is($result, "$start_lsn|streaming|5120 kB", 'check that wal_keep_segments overrides max_slot_wal_keep_size');
+
+# restore wal_keep_segments
+$result = $node_master->safe_psql('postgres', "ALTER SYSTEM SET wal_keep_segments to 0; SELECT pg_reload_conf();");
+
+# Advance WAL again without checkpoint
+advance_wal($node_master, 2);
+
+# Slot gets to 'keeping' state
+$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, pg_size_pretty(remain) as remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
+is($result, "$start_lsn|keeping|0 bytes", 'check that the slot state changes to "keeping"');
+
+# The standby still can connect to master
+$node_standby->start;
+
+$start_lsn = $node_master->lsn('write');
+$node_master->wait_for_catchup($node_standby, 'replay', $start_lsn);
+
+$node_standby->stop;
+
+ok(!find_in_log($node_standby,
+				"requested WAL segment [0-9A-F]+ has already been removed"),
+   'check that required WAL segments are still available');
+
+# Advance WAL again, the slot loses some segments.
+my $logstart = get_log_size($node_master);
+advance_wal($node_master, 5);
+$node_master->safe_psql('postgres', "CHECKPOINT;");
+
+# WARNING should be issued
+ok(find_in_log($node_master,
+			   "some replication slots have lost required WAL segments\n".
+			   ".*Slot rep1 lost 2 segment\\(s\\)\\.",
+			   $logstart),
+   'check that the warning is logged');
+
+# This slot should be broken
+$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, pg_size_pretty(remain) as remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
+is($result, "$start_lsn|lost|0 bytes", 'check that the slot state changes to "lost"');
+
+# The standby no longer can connect to the master
+$logstart = get_log_size($node_standby);
+$node_standby->start;
+
+my $failed = 0;
+for (my $i = 0 ; $i < 10000 ; $i++)
+{
+	if (find_in_log($node_standby,
+					"requested WAL segment [0-9A-F]+ has already been removed",
+					$logstart))
+	{
+		$failed = 1;
+		last;
+	}
+	usleep(100_000);
+}
+ok($failed, 'check that replication has been broken');
+
+$node_standby->stop;
+
+#####################################
+# Advance WAL of $node by $n segments
+sub advance_wal
+{
+	my ($node, $n) = @_;
+
+	# Advance by $n segments (= (16 * $n) MB) on master
+	for (my $i = 0 ; $i < $n ; $i++)
+	{
+		$node->safe_psql('postgres', "CREATE TABLE t (); DROP TABLE t; SELECT pg_switch_wal();");
+	}
+}
+
+# return the size of logfile of $node in bytes
+sub get_log_size
+{
+	my ($node) = @_;
+
+	return (stat $node->logfile)[7];
+}
+
+# find $pat in logfile of $node after $off-th byte
+sub find_in_log
+{
+	my ($node, $pat, $off) = @_;
+
+	$off = 0 unless defined $off;
+	my $log = TestLib::slurp_file($node->logfile);
+	return 0 if (length($log) <= $off);
+
+	$log = substr($log, $off);
+
+	return $log =~ m/$pat/;
+}
-- 
2.20.1


--MP_/68vU=6Ib.yoYOTdA.M=EVne
Content-Type: text/x-patch
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename=v14-0005-Documentation-for-slot-limit-feature.patch



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

* [PATCH] pg_bsd_indent: improve formatting of multiline comments
@ 2025-06-19 14:51 Aleksander Alekseev <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Aleksander Alekseev @ 2025-06-19 14:51 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Michael Paquier <michael@paquier.xyz>

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, ../../CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s+_V4=t+xgSnZm1cFw@mail.gmail.com/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 <aleksander@timescale.com>
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] 32+ 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 <aleksander@timescale.com>
@ 2025-06-19 20:33 ` Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Arseniy Mukhin @ 2025-06-19 20:33 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@timescale.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Michael Paquier <michael@paquier.xyz>

On Thu, Jun 19, 2025 at 5:51 PM Aleksander Alekseev
<aleksander@timescale.com> 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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
@ 2025-06-20 13:44   ` Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 32+ messages in thread

From: Aleksander Alekseev @ 2025-06-20 13:44 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Michael Paquier <michael@paquier.xyz>

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, ../../CAJ7c6TOp_h5Ueu8tPTnmponG84oFrm3D+zFWBwae-80do6o-rA@mail.gmail.com/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 <aleksander@timescale.com>
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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
@ 2025-06-20 13:56     ` Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Bruce Momjian @ 2025-06-20 13:56 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@timescale.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Michael Paquier <michael@paquier.xyz>

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  <bruce@momjian.us>        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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
@ 2025-06-20 14:01       ` Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 14:14         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  0 siblings, 2 replies; 32+ messages in thread

From: Aleksander Alekseev @ 2025-06-20 14:01 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Bruce Momjian <bruce@momjian.us>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Michael Paquier <michael@paquier.xyz>

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, ../../CAJ7c6TOCJG2p0Ob9Z7mXQRhkmRX_mxBay198Z173t4=PZr=yEQ@mail.gmail.com/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 <aleksander@timescale.com>
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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
@ 2025-06-20 14:14         ` Bruce Momjian <bruce@momjian.us>
  1 sibling, 0 replies; 32+ messages in thread

From: Bruce Momjian @ 2025-06-20 14:14 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@timescale.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Michael Paquier <michael@paquier.xyz>

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  <bruce@momjian.us>        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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
@ 2025-06-21 18:54         ` Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  1 sibling, 1 reply; 32+ messages in thread

From: Arseniy Mukhin @ 2025-06-21 18:54 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@timescale.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

On Fri, Jun 20, 2025 at 5:01 PM Aleksander Alekseev
<aleksander@timescale.com> 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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
@ 2025-06-23 10:42           ` Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Aleksander Alekseev @ 2025-06-23 10:42 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

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, ../../CAJ7c6TOGdVBK5P-s59c77qxaw=ydPjpzp_s3VbpHeHn3Gc1iyA@mail.gmail.com/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 <aleksander@timescale.com>
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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
@ 2025-10-23 20:25             ` Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Nathan Bossart @ 2025-10-23 20:25 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@timescale.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
@ 2025-10-27 12:13               ` Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  0 siblings, 2 replies; 32+ messages in thread

From: Aleksander Alekseev @ 2025-10-27 12:13 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

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, ../../CAJ7c6TMTzQsnKfM+_4i-4WO7=YnV4nO8ABWA6enSpdtg6DKhqQ@mail.gmail.com/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 <aleksander@timescale.com>
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 <aleksander@tigerdata.com>
Reported-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
@ 2025-10-27 14:55                 ` Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
  1 sibling, 1 reply; 32+ messages in thread

From: Nathan Bossart @ 2025-10-27 14:55 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@tigerdata.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
@ 2025-10-27 23:35                   ` Michael Paquier <michael@paquier.xyz>
  2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Michael Paquier @ 2025-10-27 23:35 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>

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 (832B, ../../aQABs_2dbXmGXDvv@paquier.xyz/2-signature.asc)
  download

^ permalink  raw  reply  [nested|flat] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
@ 2025-10-28 00:36                     ` Chao Li <li.evan.chao@gmail.com>
  2025-12-11 21:43                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Chao Li @ 2025-10-28 00:36 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>



> On Oct 28, 2025, at 07:35, Michael Paquier <michael@paquier.xyz> 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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
  2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
@ 2025-12-11 21:43                       ` Nathan Bossart <nathandbossart@gmail.com>
  2026-02-06 22:27                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Nathan Bossart @ 2025-12-11 21:43 UTC (permalink / raw)
  To: Chao Li <li.evan.chao@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>

On Tue, Oct 28, 2025 at 08:36:33AM +0800, Chao Li wrote:
> On Oct 28, 2025, at 07:35, Michael Paquier <michael@paquier.xyz> 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
From bf5e0e7ac895070ccb3b3cff9a550e4c14179e2b Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathan@postgresql.org>
Date: Thu, 11 Dec 2025 15:26:57 -0600
Subject: [PATCH v1 1/1] fix some commented undefs

---
 src/backend/access/nbtree/nbtsort.c | 2 +-
 src/backend/utils/adt/numeric.c     | 2 +-
 src/include/executor/execdebug.h    | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index d7695dc1108..5119db53a1b 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -69,8 +69,8 @@
 /*
  * DISABLE_LEADER_PARTICIPATION disables the leader's participation in
  * parallel index builds.  This may be useful as a debugging aid.
-#undef DISABLE_LEADER_PARTICIPATION
  */
+/* #define DISABLE_LEADER_PARTICIPATION */
 
 /*
  * Status record for spooling/sorting phase.  (Note we may have two of
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 2460698df01..a42a2948121 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -48,8 +48,8 @@
  * Uncomment the following to enable compilation of dump_numeric()
  * and dump_var() and to get a dump of any result produced by make_result().
  * ----------
-#define NUMERIC_DEBUG
  */
+/* #define NUMERIC_DEBUG */
 
 
 /* ----------
diff --git a/src/include/executor/execdebug.h b/src/include/executor/execdebug.h
index e5d27fb6c9a..d999a907e77 100644
--- a/src/include/executor/execdebug.h
+++ b/src/include/executor/execdebug.h
@@ -34,22 +34,22 @@
  *		EXEC_NESTLOOPDEBUG is a flag which turns on debugging of the
  *		nest loop node by NL_printf() and ENL_printf() in nodeNestloop.c
  * ----------------
-#undef EXEC_NESTLOOPDEBUG
  */
+/* #define EXEC_NESTLOOPDEBUG */
 
 /* ----------------
  *		EXEC_SORTDEBUG is a flag which turns on debugging of
  *		the ExecSort() stuff by SO_printf() in nodeSort.c
  * ----------------
-#undef EXEC_SORTDEBUG
  */
+/* #define EXEC_SORTDEBUG */
 
 /* ----------------
  *		EXEC_MERGEJOINDEBUG is a flag which turns on debugging of
  *		the ExecMergeJoin() stuff by MJ_printf() in nodeMergejoin.c
  * ----------------
-#undef EXEC_MERGEJOINDEBUG
  */
+/* #define EXEC_MERGEJOINDEBUG */
 
 /* ----------------------------------------------------------------
  *		#defines controlled by above definitions
-- 
2.39.5 (Apple Git-154)

Attachments:

  [text/plain] v1-0001-fix-some-commented-undefs.patch (2.4K, ../../aTs7A4lbcm0ThXaO@nathan/2-v1-0001-fix-some-commented-undefs.patch)
  download | inline diff:
From bf5e0e7ac895070ccb3b3cff9a550e4c14179e2b Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathan@postgresql.org>
Date: Thu, 11 Dec 2025 15:26:57 -0600
Subject: [PATCH v1 1/1] fix some commented undefs

---
 src/backend/access/nbtree/nbtsort.c | 2 +-
 src/backend/utils/adt/numeric.c     | 2 +-
 src/include/executor/execdebug.h    | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index d7695dc1108..5119db53a1b 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -69,8 +69,8 @@
 /*
  * DISABLE_LEADER_PARTICIPATION disables the leader's participation in
  * parallel index builds.  This may be useful as a debugging aid.
-#undef DISABLE_LEADER_PARTICIPATION
  */
+/* #define DISABLE_LEADER_PARTICIPATION */
 
 /*
  * Status record for spooling/sorting phase.  (Note we may have two of
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 2460698df01..a42a2948121 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -48,8 +48,8 @@
  * Uncomment the following to enable compilation of dump_numeric()
  * and dump_var() and to get a dump of any result produced by make_result().
  * ----------
-#define NUMERIC_DEBUG
  */
+/* #define NUMERIC_DEBUG */
 
 
 /* ----------
diff --git a/src/include/executor/execdebug.h b/src/include/executor/execdebug.h
index e5d27fb6c9a..d999a907e77 100644
--- a/src/include/executor/execdebug.h
+++ b/src/include/executor/execdebug.h
@@ -34,22 +34,22 @@
  *		EXEC_NESTLOOPDEBUG is a flag which turns on debugging of the
  *		nest loop node by NL_printf() and ENL_printf() in nodeNestloop.c
  * ----------------
-#undef EXEC_NESTLOOPDEBUG
  */
+/* #define EXEC_NESTLOOPDEBUG */
 
 /* ----------------
  *		EXEC_SORTDEBUG is a flag which turns on debugging of
  *		the ExecSort() stuff by SO_printf() in nodeSort.c
  * ----------------
-#undef EXEC_SORTDEBUG
  */
+/* #define EXEC_SORTDEBUG */
 
 /* ----------------
  *		EXEC_MERGEJOINDEBUG is a flag which turns on debugging of
  *		the ExecMergeJoin() stuff by MJ_printf() in nodeMergejoin.c
  * ----------------
-#undef EXEC_MERGEJOINDEBUG
  */
+/* #define EXEC_MERGEJOINDEBUG */
 
 /* ----------------------------------------------------------------
  *		#defines controlled by above definitions
-- 
2.39.5 (Apple Git-154)

^ permalink  raw  reply  [nested|flat] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
  2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-12-11 21:43                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
@ 2026-02-06 22:27                         ` Nathan Bossart <nathandbossart@gmail.com>
  2026-02-09 11:19                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Nathan Bossart @ 2026-02-06 22:27 UTC (permalink / raw)
  To: Chao Li <li.evan.chao@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>

On Thu, Dec 11, 2025 at 03:43:31PM -0600, Nathan Bossart wrote:
> Here's a patch for this.  I also changed the #undefs to #defines.

I went ahead and committed this.

-- 
nathan





^ permalink  raw  reply  [nested|flat] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
  2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-12-11 21:43                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2026-02-06 22:27                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
@ 2026-02-09 11:19                           ` Aleksander Alekseev <aleksander@tigerdata.com>
  2026-05-04 16:40                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 32+ messages in thread

From: Aleksander Alekseev @ 2026-02-09 11:19 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Nathan Bossart <nathandbossart@gmail.com>

Hi,

> > Here's a patch for this.  I also changed the #undefs to #defines.
>
> I went ahead and committed this.

Thanks, Nathan. Re-submitting v6 to make it visible by cfbot again and
in order to simplify the work of reviewers a bit.

-- 
Best regards,
Aleksander Alekseev

Attachments:

  [text/x-patch] v6-0001-pgindent-improve-formatting-of-multiline-comments.patch (2.3K, ../../CAJ7c6TPJVau3Ppih7+KubRwvG9CRpXq16L3X9bE02KuGgL95Nw@mail.gmail.com/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 <aleksander@timescale.com>
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 <aleksander@tigerdata.com>
Reported-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
  2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-12-11 21:43                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2026-02-06 22:27                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2026-02-09 11:19                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
@ 2026-05-04 16:40                             ` Tom Lane <tgl@sss.pgh.pa.us>
  2026-05-04 17:11                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2026-05-05 13:06                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  0 siblings, 2 replies; 32+ messages in thread

From: Tom Lane @ 2026-05-04 16:40 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@tigerdata.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>

Aleksander Alekseev <aleksander@tigerdata.com> writes:
> Thanks, Nathan. Re-submitting v6 to make it visible by cfbot again and
> in order to simplify the work of reviewers a bit.

I tested the v6 patch by running it on current HEAD.  Pretty nearly all
the changes it makes are improvements, but it seems like there's still
some work to be done.  In particular, in src/port/inet_aton.c it
produces this diff:

--- a/src/port/inet_aton.c
+++ b/src/port/inet_aton.c
@@ -36,7 +37,8 @@
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.  */
+ * SUCH DAMAGE. 
+ */
 
 #include "c.h"

in which not all the trailing whitespace has been removed from the
first line, causing "git diff --check" to complain:

$ git diff --check
src/port/inet_aton.c:40: trailing whitespace.
+ * SUCH DAMAGE. 

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

Another amusing diff I noticed:

--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -5713,7 +5713,7 @@ check_parent_values_in_new_partitions(Relation parent,
  * 3. In case new partitions don't contain the DEFAULT partition and the
  *	  partitioned table does not have the DEFAULT partition, the following
  *	  should be true: the sum of the bounds of new partitions should be equal
- &	  to the bound of the split partition.
+ * &	  to the bound of the split partition.
  *
  * parent:			partitioned table
  * splitPartOid:	split partition Oid

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

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

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
  2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-12-11 21:43                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2026-02-06 22:27                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2026-02-09 11:19                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2026-05-04 16:40                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
@ 2026-05-04 17:11                               ` Nathan Bossart <nathandbossart@gmail.com>
  1 sibling, 0 replies; 32+ messages in thread

From: Nathan Bossart @ 2026-05-04 17:11 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

On Mon, May 04, 2026 at 12:40:19PM -0400, Tom Lane wrote:
> Another amusing diff I noticed:
> 
> --- a/src/backend/partitioning/partbounds.c
> +++ b/src/backend/partitioning/partbounds.c
> @@ -5713,7 +5713,7 @@ check_parent_values_in_new_partitions(Relation parent,
>   * 3. In case new partitions don't contain the DEFAULT partition and the
>   *	  partitioned table does not have the DEFAULT partition, the following
>   *	  should be true: the sum of the bounds of new partitions should be equal
> - &	  to the bound of the split partition.
> + * &	  to the bound of the split partition.
>   *
>   * parent:			partitioned table
>   * splitPartOid:	split partition Oid
> 
> Clearly, this is somebody's off-by-one-key typo, and the correct
> fix is s/&/*/.  I suspect that fixing that manually is the most
> expedient answer, rather than trying to make pg_bsd_indent smart
> enough to DTRT.

+1.  This patch has been rather good at finding small mistakes like this,
which I've been manually fixing along the way.

-- 
nathan





^ permalink  raw  reply  [nested|flat] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
  2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-12-11 21:43                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2026-02-06 22:27                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2026-02-09 11:19                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2026-05-04 16:40                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
@ 2026-05-05 13:06                               ` Aleksander Alekseev <aleksander@tigerdata.com>
  1 sibling, 0 replies; 32+ messages in thread

From: Aleksander Alekseev @ 2026-05-05 13:06 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>

Hi Tom,

Thanks for your feedback.

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

Fair point. Fixed.

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

Agree.

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

Fixed in v7.

-- 
Best regards,
Aleksander Alekseev

Attachments:

  [text/x-patch] v7-0001-pgindent-improve-formatting-of-multiline-comments.patch (2.3K, ../../CAJ7c6TNVeFYAYFs0KDEVsZNPaZtKtHHq+1Mw7=pTw5Hr3g7KGA@mail.gmail.com/2-v7-0001-pgindent-improve-formatting-of-multiline-comments.patch)
  download | inline diff:
From 7c3abf671bafaf3a5425994e9cfedf5dafaf9895 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@timescale.com>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v7] pgindent: improve formatting of multiline comments

Format multiline comments like this:

/* line 1
 * line 2
 */

... into:

/*
 * line 1
 * line 2
 */

This is more consistent with what we currently have in the tree.

Author: Aleksander Alekseev <aleksander@tigerdata.com>
Reported-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s%2B_V4%3Dt%2BxgSnZm1cFw%40mail.gmail.com
---
 src/tools/pgindent/pgindent | 40 +++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index b2ec5e2914b..f4be74fc3a4 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -285,6 +285,9 @@ sub post_indent
 	# Fix run-together comments to have a tab between them
 	$source =~ s!\*/(/\*.*\*/)$!*/\t$1!gm;
 
+	# Postprocess multiline comments except for /**... and /*-... ones
+	$source =~ s!^(/\*[^\*\-].*?\*/)!postprocess_multiline_comment($1)!mgse;
+
 	## Functions
 
 	# Use a single space before '*' in function return types
@@ -293,6 +296,43 @@ sub post_indent
 	return $source;
 }
 
+sub postprocess_multiline_comment
+{
+	my $source = shift;
+	my @lines = split "\n", $source;
+
+	# Only format comments that match the expected format,
+	# or at least that could have been the author's intent.
+	if (   ($lines[0] ne "/*" && $lines[-1] ne " */")
+		or ($lines[1] !~ m!^\s+\*!))
+	{
+		return $source;
+	}
+
+	# Check each line except for the first and the last one
+	for my $i (1 .. scalar @lines - 2)
+	{
+		$lines[$i] = " *" . $lines[$i] if $lines[$i] !~ /^\s+\*/;
+	}
+
+	# Keep /* === and /* --- lines as is
+	if ($lines[0] !~ m!^/\*\s+[=-]+!)
+	{
+		$lines[0] =~ s!/\*(.+)!/\*\n *$1!;
+	}
+
+	# Keep === */ and --- */ lines as is
+	if ($lines[-1] !~ m![=-]+\s+\*/$!)
+	{
+		# also remove trailing whitespaces
+		$lines[-1] =~ s!(.+?)\s+\*/!$1\n \*/!;
+	}
+
+	$source = join "\n", @lines;
+
+	return $source;
+}
+
 sub run_indent
 {
 	my $source = shift;
-- 
2.43.0



^ permalink  raw  reply  [nested|flat] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
@ 2025-10-28 00:57                 ` Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  1 sibling, 1 reply; 32+ messages in thread

From: Chao Li @ 2025-10-28 00:57 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@tigerdata.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>



> On Oct 27, 2025, at 20:13, Aleksander Alekseev <aleksander@tigerdata.com> 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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
@ 2025-11-10 09:28                   ` Aleksander Alekseev <aleksander@tigerdata.com>
  2025-11-11 06:28                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 2 replies; 32+ messages in thread

From: Aleksander Alekseev @ 2025-11-10 09:28 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Chao Li <li.evan.chao@gmail.com>; Nathan Bossart <nathandbossart@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

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, ../../CAJ7c6TPCJz-ExBFL8q2dCkXZpUdpm=+wvTF11gDENGk39n3DYA@mail.gmail.com/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 <aleksander@timescale.com>
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 <aleksander@tigerdata.com>
Reported-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
@ 2025-11-11 06:28                     ` Chao Li <li.evan.chao@gmail.com>
  1 sibling, 0 replies; 32+ messages in thread

From: Chao Li @ 2025-11-11 06:28 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@tigerdata.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>



> On Nov 10, 2025, at 17:28, Aleksander Alekseev <aleksander@tigerdata.com> 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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
@ 2025-12-11 21:48                     ` Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  1 sibling, 1 reply; 32+ messages in thread

From: Nathan Bossart @ 2025-12-11 21:48 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@tigerdata.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Chao Li <li.evan.chao@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
@ 2025-12-12 11:32                       ` Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <alvherre@kurilemu.de>
  0 siblings, 1 reply; 32+ messages in thread

From: Aleksander Alekseev @ 2025-12-12 11:32 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Chao Li <li.evan.chao@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
@ 2025-12-12 15:53                         ` Álvaro Herrera <alvherre@kurilemu.de>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 32+ messages in thread

From: Álvaro Herrera @ 2025-12-12 15:53 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@tigerdata.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>; Chao Li <li.evan.chao@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <alvherre@kurilemu.de>
@ 2025-12-12 16:17                           ` Tom Lane <tgl@sss.pgh.pa.us>
  2025-12-12 16:23                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-12-19 20:02                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  0 siblings, 2 replies; 32+ messages in thread

From: Tom Lane @ 2025-12-12 16:17 UTC (permalink / raw)
  To: Álvaro Herrera <alvherre@kurilemu.de>; +Cc: Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>; Chao Li <li.evan.chao@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

=?utf-8?Q?=C3=81lvaro?= Herrera <alvherre@kurilemu.de> 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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <alvherre@kurilemu.de>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
@ 2025-12-12 16:23                             ` Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 18:37                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 32+ messages in thread

From: Nathan Bossart @ 2025-12-12 16:23 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Álvaro Herrera <alvherre@kurilemu.de>; Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Chao Li <li.evan.chao@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

On Fri, Dec 12, 2025 at 11:17:01AM -0500, Tom Lane wrote:
> =?utf-8?Q?=C3=81lvaro?= Herrera <alvherre@kurilemu.de> 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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <alvherre@kurilemu.de>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
  2025-12-12 16:23                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
@ 2025-12-12 18:37                               ` Tom Lane <tgl@sss.pgh.pa.us>
  2025-12-12 21:47                                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  0 siblings, 1 reply; 32+ messages in thread

From: Tom Lane @ 2025-12-12 18:37 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Álvaro Herrera <alvherre@kurilemu.de>; Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Chao Li <li.evan.chao@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

Nathan Bossart <nathandbossart@gmail.com> 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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <alvherre@kurilemu.de>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
  2025-12-12 16:23                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 18:37                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
@ 2025-12-12 21:47                                 ` Aleksander Alekseev <aleksander@tigerdata.com>
  0 siblings, 0 replies; 32+ messages in thread

From: Aleksander Alekseev @ 2025-12-12 21:47 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Nathan Bossart <nathandbossart@gmail.com>; Álvaro Herrera <alvherre@kurilemu.de>; Chao Li <li.evan.chao@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Bruce Momjian <bruce@momjian.us>; Michael Paquier <michael@paquier.xyz>

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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <alvherre@kurilemu.de>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
@ 2025-12-19 20:02                             ` Bruce Momjian <bruce@momjian.us>
  2025-12-21 22:33                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
  1 sibling, 1 reply; 32+ messages in thread

From: Bruce Momjian @ 2025-12-19 20:02 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Álvaro Herrera <alvherre@kurilemu.de>; Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>; Chao Li <li.evan.chao@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>; Michael Paquier <michael@paquier.xyz>

On Fri, Dec 12, 2025 at 11:17:01AM -0500, Tom Lane wrote:
> =?utf-8?Q?=C3=81lvaro?= Herrera <alvherre@kurilemu.de> 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  <bruce@momjian.us>        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] 32+ 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 <aleksander@timescale.com>
  2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
  2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
  2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
  2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
  2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
  2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
  2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <alvherre@kurilemu.de>
  2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
  2025-12-19 20:02                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
@ 2025-12-21 22:33                               ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 32+ messages in thread

From: Michael Paquier @ 2025-12-21 22:33 UTC (permalink / raw)
  To: Bruce Momjian <bruce@momjian.us>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Álvaro Herrera <alvherre@kurilemu.de>; Aleksander Alekseev <aleksander@tigerdata.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>; Chao Li <li.evan.chao@gmail.com>; Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>

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 <alvherre@kurilemu.de> 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 (832B, ../../aUh1q5twC8WqXATK@paquier.xyz/2-signature.asc)
  download

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


end of thread, other threads:[~2026-05-05 13:06 UTC | newest]

Thread overview: 32+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-12-21 08:33 [PATCH 4/6] TAP test for the slot limit feature Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
2025-06-19 14:51 [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
2025-06-19 20:33 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
2025-06-20 13:44   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
2025-06-20 13:56     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
2025-06-20 14:01       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
2025-06-20 14:14         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
2025-06-21 18:54         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
2025-06-23 10:42           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@timescale.com>
2025-10-23 20:25             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
2025-10-27 12:13               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
2025-10-27 14:55                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
2025-10-27 23:35                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>
2025-10-28 00:36                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
2025-12-11 21:43                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
2026-02-06 22:27                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
2026-02-09 11:19                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
2026-05-04 16:40                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
2026-05-04 17:11                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
2026-05-05 13:06                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
2025-10-28 00:57                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
2025-11-10 09:28                   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
2025-11-11 06:28                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Chao Li <li.evan.chao@gmail.com>
2025-12-11 21:48                     ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
2025-12-12 11:32                       ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
2025-12-12 15:53                         ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Álvaro Herrera <alvherre@kurilemu.de>
2025-12-12 16:17                           ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
2025-12-12 16:23                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <nathandbossart@gmail.com>
2025-12-12 18:37                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <tgl@sss.pgh.pa.us>
2025-12-12 21:47                                 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <aleksander@tigerdata.com>
2025-12-19 20:02                             ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Bruce Momjian <bruce@momjian.us>
2025-12-21 22:33                               ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Michael Paquier <michael@paquier.xyz>

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