pgindent to ignore build directories

Поиск
Список
Период
Сортировка
Искать

pgindent to ignore build directories

От:
Peter Eisentraut <peter@eisentraut.org>
Дата:
Вложения:
A problem I'm having is that if I'm having a build directory inside the 
source tree

     meson setup build

(as is documented) and then run pgindent

     src/tools/pgindent/pgindent .

it descends into the build directory and then chokes on various files in 
there.  (exclude_file_patterns doesn't help because those patterns are 
applied relative to the source directory.)

A subproblem is that if pgindent fails on many files, it doesn't clean 
up after itself but leaves many pgsrc*.BAK files lying around.  The 
first patch fixes that.

Then, my first idea was to add an option to pgindent to exclude 
directories from being processed.  Like

     src/tools/pgindent/pgindent . --exclude-dir=build

The second patch implements that.

But then I had the idea that we could recognize build directories 
automatically by checking what files they contain.  The third patch 
implements that.  That way, my initial pgindent invocation above works 
out of the box and I don't have to remember to enumerate the build 
directories on the command line.

(So the second patch is maybe obsolete, but the third one builds on it, 
so I left it in here for discussion.  People seem to have a variety of 
workflows, so let's see what everyone wants.)

Re: pgindent to ignore build directories

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut  writes:
> A problem I'm having is that if I'm having a build directory inside the 
> source tree
>      meson setup build
> (as is documented) and then run pgindent
>      src/tools/pgindent/pgindent .
> it descends into the build directory and then chokes on various files in 
> there.

Right, we should handle that.

> A subproblem is that if pgindent fails on many files, it doesn't clean 
> up after itself but leaves many pgsrc*.BAK files lying around.  The 
> first patch fixes that.

I object to this patch.  src/tools/pgindent/README documents that
the presence of those files is useful for detecting where pgindent
failed.  Without them there's not an easy signal.

> Then, my first idea was to add an option to pgindent to exclude 
> directories from being processed.  Like
>      src/tools/pgindent/pgindent . --exclude-dir=build
> The second patch implements that.

That seems a bit tedious.

> But then I had the idea that we could recognize build directories 
> automatically by checking what files they contain.  The third patch 
> implements that.  That way, my initial pgindent invocation above works 
> out of the box and I don't have to remember to enumerate the build 
> directories on the command line.

+1 for this one.  I could do without 0002, for myself; what use would
it have once the automatic logic exists?

			regards, tom lane


Re: pgindent to ignore build directories

От:
Nazir Bilal Yavuz <byavuz81@gmail.com>
Дата:
Hi,

On Thu, 24 Sept 2026 at 17:29, Tom Lane  wrote:
>
> Peter Eisentraut  writes:
> > A subproblem is that if pgindent fails on many files, it doesn't clean
> > up after itself but leaves many pgsrc*.BAK files lying around.  The
> > first patch fixes that.
>
> I object to this patch.  src/tools/pgindent/README documents that
> the presence of those files is useful for detecting where pgindent
> failed.  Without them there's not an easy signal.

I remember being frustrated with too many pgsrc*.BAK files but that
was when pgindent processed the build folder. I think we might not
need 0001 after 0003.

--
Regards,
Nazir Bilal Yavuz
Microsoft


Re: pgindent to ignore build directories

От:
Jelte Fennema-Nio <postgres@jeltef.nl>
Дата:
On Thu, 24 Sept 2026 at 16:29, Tom Lane  wrote:
> I object to this patch.  src/tools/pgindent/README documents that
> the presence of those files is useful for detecting where pgindent
> failed.  Without them there's not an easy signal.

Hard disagree. I don't think BAK files serve that purpose well, and
they should be removed always imo (or possibly not even created in the
first place). There are two much better signals for detecting whether
and how pgindent fails:
1. stderr of pgindent
2. exit code of pgindent

The BAK files have useless names (e.g. pgsrcq4373.BAK). So if you want
to use them to detect where pgindent failed you have to look at their
contents and figure out the original based on that. While stderr
actually shows you what file failed and what the problem was, e.g.:

Failure in ./build/src/backend/bootstrap/bootparse.h: Error@82:
Statement nesting error
Error@113: Stuff missing from end of file

But I do agree that the pgindent README should call out these better
methods when changing the BAK file behaviour.


Re: pgindent to ignore build directories

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Jelte Fennema-Nio  writes:
> On Thu, 24 Sept 2026 at 16:29, Tom Lane  wrote:
>> I object to this patch.  src/tools/pgindent/README documents that
>> the presence of those files is useful for detecting where pgindent
>> failed.  Without them there's not an easy signal.

> Hard disagree. I don't think BAK files serve that purpose well, and
> they should be removed always imo (or possibly not even created in the
> first place). There are two much better signals for detecting whether
> and how pgindent fails:
> 1. stderr of pgindent
> 2. exit code of pgindent

You fail to get my point.  When doing a full-tree run, it's not enough
to get a binary pass/fail signal: it's necessary to know which files
pgindent failed on, so you can go look at them and fix them.  IMO
the .BAK files are actually quite well adapted for this, because you
can go fix the first failing file, remove its .BAK file, and then the
other .BAK files are still there to remind you what else to look at.
pgindent's exit code is utterly inadequate for that.  And even if it
prints just what you need to know on stderr, that's transient data
that has probably scrolled off your terminal window by the time you
finished with the first problem.

Is that perfect?  Hardly; I can definitely think of better UX
experiences.  But it beats having zero bread-crumbs, which is where
Peter's patch would leave us.  If you want to get rid of the .BAK
files, provide a superior substitute *first*.

			regards, tom lane


Re: pgindent to ignore build directories

От:
Jelte Fennema-Nio <postgres@jeltef.nl>
Дата:
On Mon, 28 Sept 2026 at 05:25, Tom Lane  wrote:
> And even if it
> prints just what you need to know on stderr, that's transient data
> that has probably scrolled off your terminal window by the time you
> finished with the first problem.

That seems easily solved by piping stderr to a file (e.g. using tee):

src/tools/pgindent/pgindent . 2>| tee pgindent-errors.log

Another option is to simply rerun pgindent again after fixing a file
to get the rest of the failing files.

I'm personally much more annoyed by a bunch of random garbage files
being created in my working directory than by having to do either of
those when I want to run pgindent on my full tree.


Re: pgindent to ignore build directories

От:
Peter Eisentraut <peter@eisentraut.org>
Дата:
Вложения:
On 24.09.26 17:43, Nazir Bilal Yavuz wrote:
> On Thu, 24 Sept 2026 at 17:29, Tom Lane  wrote:
>>
>> Peter Eisentraut  writes:
>>> A subproblem is that if pgindent fails on many files, it doesn't clean
>>> up after itself but leaves many pgsrc*.BAK files lying around.  The
>>> first patch fixes that.
>>
>> I object to this patch.  src/tools/pgindent/README documents that
>> the presence of those files is useful for detecting where pgindent
>> failed.  Without them there's not an easy signal.
> 
> I remember being frustrated with too many pgsrc*.BAK files but that
> was when pgindent processed the build folder. I think we might not
> need 0001 after 0003.

Here is an updated patch that just implements automatic skipping of 
build directories.  It's quite compact and seems universally useful.

Re: pgindent to ignore build directories

От:
Nazir Bilal Yavuz <byavuz81@gmail.com>
Дата:
Hi,

On Thu, 1 Oct 2026 at 10:04, Peter Eisentraut  wrote:
>
> On 24.09.26 17:43, Nazir Bilal Yavuz wrote:
> > On Thu, 24 Sept 2026 at 17:29, Tom Lane  wrote:
> >>
> >> Peter Eisentraut  writes:
> >>> A subproblem is that if pgindent fails on many files, it doesn't clean
> >>> up after itself but leaves many pgsrc*.BAK files lying around.  The
> >>> first patch fixes that.
> >>
> >> I object to this patch.  src/tools/pgindent/README documents that
> >> the presence of those files is useful for detecting where pgindent
> >> failed.  Without them there's not an easy signal.
> >
> > I remember being frustrated with too many pgsrc*.BAK files but that
> > was when pgindent processed the build folder. I think we might not
> > need 0001 after 0003.
>
> Here is an updated patch that just implements automatic skipping of
> build directories.  It's quite compact and seems universally useful.

I agree. I tested v2 with both meson and autoconf and it works
correctly, v2 LGTM.


-- 
Regards,
Nazir Bilal Yavuz
Microsoft


Re: pgindent to ignore build directories

От:
Peter Eisentraut <peter@eisentraut.org>
Дата:
On 01.10.26 11:00, Nazir Bilal Yavuz wrote:
> Hi,
> 
> On Thu, 1 Oct 2026 at 10:04, Peter Eisentraut  wrote:
>>
>> On 24.09.26 17:43, Nazir Bilal Yavuz wrote:
>>> On Thu, 24 Sept 2026 at 17:29, Tom Lane  wrote:
>>>>
>>>> Peter Eisentraut  writes:
>>>>> A subproblem is that if pgindent fails on many files, it doesn't clean
>>>>> up after itself but leaves many pgsrc*.BAK files lying around.  The
>>>>> first patch fixes that.
>>>>
>>>> I object to this patch.  src/tools/pgindent/README documents that
>>>> the presence of those files is useful for detecting where pgindent
>>>> failed.  Without them there's not an easy signal.
>>>
>>> I remember being frustrated with too many pgsrc*.BAK files but that
>>> was when pgindent processed the build folder. I think we might not
>>> need 0001 after 0003.
>>
>> Here is an updated patch that just implements automatic skipping of
>> build directories.  It's quite compact and seems universally useful.
> 
> I agree. I tested v2 with both meson and autoconf and it works
> correctly, v2 LGTM.

Committed, thanks.



FAQ