agora inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH 4/4] Fix a bug in pg_dump's --binary-upgrade code
7+ messages / 5 participants
[nested] [flat]

* [PATCH 4/4] Fix a bug in pg_dump's --binary-upgrade code
@ 2017-04-26 07:03  amit <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: amit @ 2017-04-26 07:03 UTC (permalink / raw)

Said bug caused pg_dump to emit invalid command to attach a partition
to its parent.
---
 src/bin/pg_dump/pg_dump.c | 50 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 15 deletions(-)

diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index a3a41d4d34..5e6845a495 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -15427,13 +15427,43 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
 				{
 					TableInfo  *parentRel = parents[k];
 
-					appendPQExpBuffer(q, "ALTER TABLE ONLY %s INHERIT ",
-									  fmtId(tbinfo->dobj.name));
+					/* In the partitioning case, we alter the parent */
+					if (tbinfo->ispartition)
+						appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+											fmtId(parentRel->dobj.name));
+					else
+						appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+											fmtId(tbinfo->dobj.name));
+
+					if (tbinfo->ispartition)
+						appendPQExpBuffer(q, "ATTACH PARTITION ");
+					else
+						appendPQExpBuffer(q, "INHERIT ");
+
+					/* Add schema-name to the appropriate table */
 					if (parentRel->dobj.namespace != tbinfo->dobj.namespace)
-						appendPQExpBuffer(q, "%s.",
+					{
+						if (tbinfo->ispartition)
+						{
+							/* Partition name */
+							appendPQExpBuffer(q, "%s.",
+								fmtId(tbinfo->dobj.namespace->dobj.name));
+							appendPQExpBuffer(q, "%s",
+								fmtId(tbinfo->dobj.name));
+						}
+						else
+						{
+							/* Inheritance parent name */
+							appendPQExpBuffer(q, "%s.",
 								fmtId(parentRel->dobj.namespace->dobj.name));
-					appendPQExpBuffer(q, "%s;\n",
-									  fmtId(parentRel->dobj.name));
+							appendPQExpBuffer(q, "%s;\n",
+								fmtId(parentRel->dobj.name));
+						}
+					}
+
+					/* Partition needs specifying the bounds */
+					if (tbinfo->ispartition)
+						appendPQExpBuffer(q, " %s;\n", tbinfo->partbound);
 				}
 			}
 
@@ -15445,16 +15475,6 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
 								  tbinfo->reloftype);
 			}
 
-			if (tbinfo->ispartition)
-			{
-				appendPQExpBufferStr(q, "\n-- For binary upgrade, set up partitions this way.\n");
-				appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
-								  fmtId(tbinfo->parents[0]->dobj.name));
-				appendPQExpBuffer(q, "ATTACH PARTITION %s %s;\n",
-								  fmtId(tbinfo->dobj.name),
-								  tbinfo->partbound);
-			}
-
 			appendPQExpBufferStr(q, "\n-- For binary upgrade, set heap's relfrozenxid and relminmxid\n");
 			appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"
 							  "SET relfrozenxid = '%u', relminmxid = '%u'\n"
-- 
2.11.0


--------------AD54DE7AD3E63838CF6BC39C
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


-- 
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

--------------AD54DE7AD3E63838CF6BC39C--





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

* [PATCH 3/5] Fix a bug in pg_dump's --binary-upgrade code
@ 2017-04-26 07:03  amit <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: amit @ 2017-04-26 07:03 UTC (permalink / raw)

Said bug caused pg_dump to emit invalid command to attach a partition
to its parent.
---
 src/bin/pg_dump/pg_dump.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 5016c2de74..5f3ec51011 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -15488,7 +15488,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
 				appendPQExpBufferStr(q, "::pg_catalog.regclass;\n");
 			}
 
-			if (numParents > 0)
+			/* Note that partitions are handled differently (see below) */
+			if (numParents > 0 && !tbinfo->partitionOf)
 			{
 				appendPQExpBufferStr(q, "\n-- For binary upgrade, set up inheritance this way.\n");
 				for (k = 0; k < numParents; k++)
-- 
2.11.0


--------------7C4A920427E010BDD0F66129
Content-Type: text/x-diff;
 name="0004-Change-the-way-pg_dump-retrieves-partitioning-info.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0004-Change-the-way-pg_dump-retrieves-partitioning-info.patc";
 filename*1="h"



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

* [PATCH 5/8] Optimize allocations in bringetbitmap
@ 2021-03-02 18:57  Tomas Vondra <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: Tomas Vondra @ 2021-03-02 18:57 UTC (permalink / raw)

The bringetbitmap function allocates memory for various purposes, which
may be quite expensive, depending on the number of scan keys. Instead of
allocating them separately, allocate one bit chunk of memory an carve it
into smaller pieces as needed - all the pieces have the same lifespan,
and it saves quite a bit of CPU and memory overhead.

Author: Tomas Vondra <[email protected]>
Discussion: https://postgr.es/m/[email protected]
---
 src/backend/access/brin/brin.c | 60 ++++++++++++++++++++++++++--------
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 9f2656b8d9..1f82e965f9 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -373,6 +373,9 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
 	int		   *nkeys,
 			   *nnullkeys;
 	int			keyno;
+	char	   *ptr;
+	Size		len;
+	char	   *tmp PG_USED_FOR_ASSERTS_ONLY;
 
 	opaque = (BrinOpaque *) scan->opaque;
 	bdesc = opaque->bo_bdesc;
@@ -402,15 +405,52 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
 	 * We keep null and regular keys separate, so that we can pass just the
 	 * regular keys to the consistent function easily.
 	 *
+	 * To reduce the allocation overhead, we allocate one big chunk and then
+	 * carve it into smaller arrays ourselves. All the pieces have exactly the
+	 * same lifetime, so that's OK.
+	 *
 	 * XXX The widest table can have ~1600 attributes, so this may allocate a
 	 * couple kilobytes of memory). We could invent a more compact approach
 	 * (with just space for used attributes) but that would make the matching
 	 * more complicated, so it may not be a win.
 	 */
-	keys = palloc0(sizeof(ScanKey *) * bdesc->bd_tupdesc->natts);
-	nullkeys = palloc0(sizeof(ScanKey *) * bdesc->bd_tupdesc->natts);
-	nkeys = palloc0(sizeof(int) * bdesc->bd_tupdesc->natts);
-	nnullkeys = palloc0(sizeof(int) * bdesc->bd_tupdesc->natts);
+	len =
+		MAXALIGN(sizeof(ScanKey *) * bdesc->bd_tupdesc->natts) +	/* regular keys */
+		MAXALIGN(sizeof(ScanKey) * scan->numberOfKeys) * bdesc->bd_tupdesc->natts +
+		MAXALIGN(sizeof(int) * bdesc->bd_tupdesc->natts) +
+		MAXALIGN(sizeof(ScanKey *) * bdesc->bd_tupdesc->natts) +	/* NULL keys */
+		MAXALIGN(sizeof(ScanKey) * scan->numberOfKeys) * bdesc->bd_tupdesc->natts +
+		MAXALIGN(sizeof(int) * bdesc->bd_tupdesc->natts);
+
+	ptr = palloc(len);
+	tmp = ptr;
+
+	keys = (ScanKey **) ptr;
+	ptr += MAXALIGN(sizeof(ScanKey *) * bdesc->bd_tupdesc->natts);
+
+	nullkeys = (ScanKey **) ptr;
+	ptr += MAXALIGN(sizeof(ScanKey *) * bdesc->bd_tupdesc->natts);
+
+	nkeys = (int *) ptr;
+	ptr += MAXALIGN(sizeof(int) * bdesc->bd_tupdesc->natts);
+
+	nnullkeys = (int *) ptr;
+	ptr += MAXALIGN(sizeof(int) * bdesc->bd_tupdesc->natts);
+
+	for (int i = 0; i < bdesc->bd_tupdesc->natts; i++)
+	{
+		keys[i] = (ScanKey *) ptr;
+		ptr += MAXALIGN(sizeof(ScanKey) * scan->numberOfKeys);
+
+		nullkeys[i] = (ScanKey *) ptr;
+		ptr += MAXALIGN(sizeof(ScanKey) * scan->numberOfKeys);
+	}
+
+	Assert(tmp + len == ptr);
+
+	/* zero the number of keys */
+	memset(nkeys, 0, sizeof(int) * bdesc->bd_tupdesc->natts);
+	memset(nnullkeys, 0, sizeof(int) * bdesc->bd_tupdesc->natts);
 
 	/*
 	 * Preprocess the scan keys - split them into per-attribute arrays.
@@ -444,9 +484,9 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
 		{
 			FmgrInfo   *tmp;
 
-			/* No key/null arrays for this attribute. */
-			Assert((keys[keyattno - 1] == NULL) && (nkeys[keyattno - 1] == 0));
-			Assert((nullkeys[keyattno - 1] == NULL) && (nnullkeys[keyattno - 1] == 0));
+			/* First time we see this attribute, so no key/null keys. */
+			Assert(nkeys[keyattno - 1] == 0);
+			Assert(nnullkeys[keyattno - 1] == 0);
 
 			tmp = index_getprocinfo(idxRel, keyattno,
 									BRIN_PROCNUM_CONSISTENT);
@@ -457,17 +497,11 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
 		/* Add key to the proper per-attribute array. */
 		if (key->sk_flags & SK_ISNULL)
 		{
-			if (!nullkeys[keyattno - 1])
-				nullkeys[keyattno - 1] = palloc0(sizeof(ScanKey) * scan->numberOfKeys);
-
 			nullkeys[keyattno - 1][nnullkeys[keyattno - 1]] = key;
 			nnullkeys[keyattno - 1]++;
 		}
 		else
 		{
-			if (!keys[keyattno - 1])
-				keys[keyattno - 1] = palloc0(sizeof(ScanKey) * scan->numberOfKeys);
-
 			keys[keyattno - 1][nkeys[keyattno - 1]] = key;
 			nkeys[keyattno - 1]++;
 		}
-- 
2.26.2


--------------AC3FFB734F56C5F52D422EFC
Content-Type: text/x-patch; charset=UTF-8;
 name="0006-BRIN-bloom-indexes-20210305.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment;
 filename="0006-BRIN-bloom-indexes-20210305.patch"



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

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
@ 2026-02-09 11:19  Aleksander Alekseev <[email protected]>
  0 siblings, 1 reply; 7+ messages in thread

From: Aleksander Alekseev @ 2026-02-09 11:19 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Nathan Bossart <[email protected]>

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 <[email protected]>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v6] pgindent: improve formatting of multiline comments

Format multiline comments like this:

/* line 1
 * line 2
 */

... into:

/*
 * line 1
 * line 2
 */

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

Author: Aleksander Alekseev <[email protected]>
Reported-by: Michael Paquier <[email protected]>
Reviewed-by: Arseniy Mukhin <[email protected]>
Reviewed-by: Nathan Bossart <[email protected]>
Discussion: https://postgr.es/m/CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s%2B_V4%3Dt%2BxgSnZm1cFw%40mail.gmail.com
---
 src/tools/pgindent/pgindent | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

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



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

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
@ 2026-05-04 16:40  Tom Lane <[email protected]>
  parent: Aleksander Alekseev <[email protected]>
  0 siblings, 2 replies; 7+ messages in thread

From: Tom Lane @ 2026-05-04 16:40 UTC (permalink / raw)
  To: Aleksander Alekseev <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Nathan Bossart <[email protected]>

Aleksander Alekseev <[email protected]> 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] 7+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
@ 2026-05-04 17:11  Nathan Bossart <[email protected]>
  parent: Tom Lane <[email protected]>
  1 sibling, 0 replies; 7+ messages in thread

From: Nathan Bossart @ 2026-05-04 17:11 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Aleksander Alekseev <[email protected]>; PostgreSQL Hackers <[email protected]>

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] 7+ messages in thread

* Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
@ 2026-05-05 13:06  Aleksander Alekseev <[email protected]>
  parent: Tom Lane <[email protected]>
  1 sibling, 0 replies; 7+ messages in thread

From: Aleksander Alekseev @ 2026-05-05 13:06 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Nathan Bossart <[email protected]>

Hi Tom,

Thanks for your feedback.

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

Fair point. Fixed.

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

Agree.

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

Fixed in v7.

-- 
Best regards,
Aleksander Alekseev


Attachments:

  [text/x-patch] v7-0001-pgindent-improve-formatting-of-multiline-comments.patch (2.3K, ../../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 <[email protected]>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v7] pgindent: improve formatting of multiline comments

Format multiline comments like this:

/* line 1
 * line 2
 */

... into:

/*
 * line 1
 * line 2
 */

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

Author: Aleksander Alekseev <[email protected]>
Reported-by: Michael Paquier <[email protected]>
Reviewed-by: Arseniy Mukhin <[email protected]>
Reviewed-by: Nathan Bossart <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s%2B_V4%3Dt%2BxgSnZm1cFw%40mail.gmail.com
---
 src/tools/pgindent/pgindent | 40 +++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

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



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


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

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-04-26 07:03 [PATCH 3/5] Fix a bug in pg_dump's --binary-upgrade code amit <[email protected]>
2017-04-26 07:03 [PATCH 4/4] Fix a bug in pg_dump's --binary-upgrade code amit <[email protected]>
2021-03-02 18:57 [PATCH 5/8] Optimize allocations in bringetbitmap Tomas Vondra <[email protected]>
2026-02-09 11:19 Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>
2026-05-04 16:40 ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Tom Lane <[email protected]>
2026-05-04 17:11   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Nathan Bossart <[email protected]>
2026-05-05 13:06   ` Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments Aleksander Alekseev <[email protected]>

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