pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: Chao Li <li.evan.chao@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org
Subject: Re: postgresql.conf.sample tab width
Date: Sun, 30 Aug 2026 11:48:12 -0500
Message-ID: <apRezMywHRuR5h-6@nathan> (raw)
In-Reply-To: <aRyf9XOgRhHn-AiO@nathan>
References: <aReNUKdMgKxLqmq7@nathan>
	<3230808.1763151915@sss.pgh.pa.us>
	<aRefX8JOs_3VbErE@nathan>
	<3238135.1763156048@sss.pgh.pa.us>
	<aRehOVyEMFIxl5rE@nathan>
	<aRtugij0CQTbpmIx@nathan>
	<EE0918D4-F05C-4047-910C-F0DED136ADE7@gmail.com>
	<aRyf9XOgRhHn-AiO@nathan>

I noticed that initdb still adds tabs to postgresql.conf.  Here is a patch
to fix that, which simplifies replace_guc_value() a bit.

-- 
nathan

Attachments:

v1-0001-initdb-Pad-rewritten-GUC-lines-with-spaces-not-ta.patch (text/plain, 2.4K) download From 7894bcefd428bd77c926a605b620e946a5b86ade Mon Sep 17 00:00:00 2001 From: Nathan Bossart <nathan@postgresql.org> Date: Sun, 30 Aug 2026 11:41:41 -0500 Subject: [PATCH v1 1/1] initdb: Pad rewritten GUC lines with spaces, not tabs. 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

view thread (12+ messages)  latest in thread

Message-ID: <apRezMywHRuR5h-6@nathan>
Permalink:  ../apRezMywHRuR5h-6@nathan/
Also on:    postgresql.org/message-id/apRezMywHRuR5h-6@nathan

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: nathandbossart@gmail.com, li.evan.chao@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: postgresql.conf.sample tab width
  In-Reply-To: <apRezMywHRuR5h-6@nathan>
  References: <aReNUKdMgKxLqmq7@nathan> <3230808.1763151915@sss.pgh.pa.us> <aRefX8JOs_3VbErE@nathan> <3238135.1763156048@sss.pgh.pa.us> <aRehOVyEMFIxl5rE@nathan> <aRtugij0CQTbpmIx@nathan> <EE0918D4-F05C-4047-910C-F0DED136ADE7@gmail.com> <aRyf9XOgRhHn-AiO@nathan> <apRezMywHRuR5h-6@nathan>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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