From a8b82e80140193402eb007b40904e29f8d766e50 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 5 May 2026 13:57:13 -0400
Subject: [PATCH v6] Make pg_bsd_indent add a space between comma and period.

Formatting of variadic functions and struct literals with named fields
used to be ugly due to pg_bsd_indent treating period as always being a
binary operator.  After a comma, it's not that, so insert a space.

Bump pg_bsd_indent's version so that people who use out-of-tree
copies will know they need to update.

Author: Andreas Karlsson <andreas@proxel.se>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/c3327be8-09e2-46a1-88b4-228a339d6916@proxel.se
---
 src/tools/pg_bsd_indent/args.c                      | 2 +-
 src/tools/pg_bsd_indent/indent.c                    | 2 ++
 src/tools/pg_bsd_indent/tests/declarations.0.stdout | 2 +-
 src/tools/pg_bsd_indent/tests/struct.0              | 2 ++
 src/tools/pg_bsd_indent/tests/struct.0.stdout       | 2 ++
 src/tools/pgindent/pgindent                         | 2 +-
 6 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/tools/pg_bsd_indent/args.c b/src/tools/pg_bsd_indent/args.c
index 5fa7e6b038c..763a03a23b5 100644
--- a/src/tools/pg_bsd_indent/args.c
+++ b/src/tools/pg_bsd_indent/args.c
@@ -51,7 +51,7 @@ static char sccsid[] = "@(#)args.c	8.1 (Berkeley) 6/6/93";
 #include "indent_globs.h"
 #include "indent.h"
 
-#define INDENT_VERSION	"2.1.2"
+#define INDENT_VERSION	"2.1.3"
 
 /* profile types */
 #define	PRO_SPECIAL	1	/* special case */
diff --git a/src/tools/pg_bsd_indent/indent.c b/src/tools/pg_bsd_indent/indent.c
index 736f350f145..1a29409173b 100644
--- a/src/tools/pg_bsd_indent/indent.c
+++ b/src/tools/pg_bsd_indent/indent.c
@@ -1013,6 +1013,8 @@ check_type:
 
 	case period:		/* treat a period kind of like a binary
 				 * operation */
+	    if (ps.want_blank && ps.last_token == comma)
+	        *e_code++ = ' ';
 	    *e_code++ = '.';	/* move the period into line */
 	    ps.want_blank = false;	/* don't put a blank after a period */
 	    break;
diff --git a/src/tools/pg_bsd_indent/tests/declarations.0.stdout b/src/tools/pg_bsd_indent/tests/declarations.0.stdout
index ab5a447a8bc..baa6bb55c78 100644
--- a/src/tools/pg_bsd_indent/tests/declarations.0.stdout
+++ b/src/tools/pg_bsd_indent/tests/declarations.0.stdout
@@ -54,7 +54,7 @@ int_create(void)
 static
 _attribute_printf(1, 2)
 void
-print_error(const char *fmt,...)
+print_error(const char *fmt, ...)
 {
 
 }
diff --git a/src/tools/pg_bsd_indent/tests/struct.0 b/src/tools/pg_bsd_indent/tests/struct.0
index 83142bfb197..6f65e461331 100644
--- a/src/tools/pg_bsd_indent/tests/struct.0
+++ b/src/tools/pg_bsd_indent/tests/struct.0
@@ -19,3 +19,5 @@ void u(struct x a) {
 	int b;
 	struct y c = (struct y *)&a;
 }
+
+static struct foo f = { .a = 1,.b=2 };
diff --git a/src/tools/pg_bsd_indent/tests/struct.0.stdout b/src/tools/pg_bsd_indent/tests/struct.0.stdout
index 38613128654..69e321ca05f 100644
--- a/src/tools/pg_bsd_indent/tests/struct.0.stdout
+++ b/src/tools/pg_bsd_indent/tests/struct.0.stdout
@@ -21,3 +21,5 @@ u(struct x a)
 	int		b;
 	struct y	c = (struct y *)&a;
 }
+
+static struct foo f = {.a = 1, .b = 2};
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index b2ec5e2914b..d035b53699b 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -35,7 +35,7 @@ my $bak_to_cleanup;
 END { unlink $bak_to_cleanup if defined $bak_to_cleanup; }
 
 # Update for pg_bsd_indent version
-my $INDENT_VERSION = "2.1.2";
+my $INDENT_VERSION = "2.1.3";
 
 # Our standard indent settings
 my $indent_opts =
-- 
2.47.3

