agora inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
[PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
37+ messages / 1 participants
[nested] [flat]

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--






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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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

* [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs.
@ 2026-08-30 16:41 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 37+ messages in thread

From: Nathan Bossart @ 2026-08-30 16:41 UTC (permalink / raw)

Commit f63ae72bbc converted postgresql.conf.sample to spaces so
that it lines up at any tab width, but replace_guc_value() still
pads with tabs when it re-aligns the trailing comment of a setting
it rewrites.  The postgresql.conf that initdb generates therefore
mixes the two.

To fix, pad with spaces.  While at it, simplify the calculation of
the original comment column: with no tabs left in the sample file
or in the lines we write out in its place, the de-tab-ifying loop
is only ever counting bytes, so have it count bytes directly.

Oversight in commit f63ae72bbc.

Discussion: https://postgr.es/m/aReNUKdMgKxLqmq7%40nathan
Backpatch-through: 19
---
 src/bin/initdb/initdb.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b3d496372ad..86d42a98a27 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -587,37 +587,16 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
 		{
 			/*
 			 * We try to preserve original indentation, which is tedious.
-			 * oldindent and newindent are measured in de-tab-ified columns.
 			 */
-			const char *ptr;
-			int			oldindent = 0;
-			int			newindent;
+			int			oldindent = (int) (where - lines[i]);
+			int			newindent = newline->len;
 
-			for (ptr = lines[i]; ptr < where; ptr++)
-			{
-				if (*ptr == '\t')
-					oldindent += 8 - (oldindent % 8);
-				else
-					oldindent++;
-			}
-			/* ignore the possibility of tabs in guc_value */
-			newindent = newline->len;
-			/* append appropriate tabs and spaces, forcing at least one */
+			/* append appropriate spaces, forcing at least one */
 			oldindent = Max(oldindent, newindent + 1);
 			while (newindent < oldindent)
 			{
-				int			newindent_if_tab = newindent + 8 - (newindent % 8);
-
-				if (newindent_if_tab <= oldindent)
-				{
-					appendPQExpBufferChar(newline, '\t');
-					newindent = newindent_if_tab;
-				}
-				else
-				{
-					appendPQExpBufferChar(newline, ' ');
-					newindent++;
-				}
+				appendPQExpBufferChar(newline, ' ');
+				newindent++;
 			}
 			/* and finally append the old comment */
 			appendPQExpBufferStr(newline, where);
-- 
2.55.0


--LmuKoVBvdv4SZ7R6--





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


end of thread, other threads:[~2026-08-30 16:41 UTC | newest]

Thread overview: 37+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>
2026-08-30 16:41 [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. Nathan Bossart <nathan@postgresql.org>

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