postgresql/src/tools/pgindent
Tom Lane 70353e463c Sync typedefs.list with buildfarm, for real this time.
In commit da256a4a7, I manually added some typedef names to the
buildfarm-generated list so as not to cause any formatting regressions
compared to the prior manually-updated list.

About half of the additions were injection-point-related names.
It turns out that those were missing because none of the buildfarm
animals contributing typedef lists were building with
--enable-injection-points.  I rectified that on my animal sifaka,
and now those are in the list available from the buildfarm.

The other half were typedefs that didn't show up in the generated list
because our method for collecting that doesn't catch names that are
not used to declare any C variables or fields.  Such a typedef name
doesn't really add a lot of value, so we decided to get rid of them,
and that's now been done in commits 110eb4aef and be5942aee.  (Note:
I'm pretty sure there are some remaining cases of that, but we've
already accepted the ensuing odd formatting of the typedef declaration
itself.  The present fixes only dealt with typedefs that had been
manually added to typedefs.list during the v17 development cycle.)

Hence, we can now install a verbatim copy of the buildfarm's list
and not have it affect anything.  The only change is to add
InjectionPointCallback, which I'd omitted from da256a4a7 because
it chanced not to affect any pgindent decisions.

Discussion: https://postgr.es/m/1919000.1715815925@sss.pgh.pa.us
2024-05-17 11:41:24 -04:00
..
README Doc: update src/tools/pgindent/README for current practice. 2024-05-15 19:02:14 -04:00
exclude_file_patterns Exclude files generated by generate-wait_event_types.pl from pgindent 2023-12-31 18:06:56 +09:00
perltidyrc Make agreed-on updates in perltidy options. 2023-05-19 16:43:57 -04:00
pgindent Activate perlcritic InputOutput::RequireCheckedSyscalls and fix resulting warnings 2024-03-19 07:09:31 +01:00
pgindent.man Rename pgindent options 2023-12-20 22:37:57 +00:00
pgperltidy Allow and require passing files on command line of pgperltidy 2023-06-21 16:20:26 +02:00
typedefs.list Sync typedefs.list with buildfarm, for real this time. 2024-05-17 11:41:24 -04:00

README

pgindent'ing the PostgreSQL source tree
=======================================

pgindent is used to maintain uniform layout style in our C and Perl code,
and should be run for every commit. There are additional code beautification
tasks which should be performed at least once per release cycle.

You might find this blog post interesting:
http://adpgtech.blogspot.com/2015/05/running-pgindent-on-non-core-code-or.html


PREREQUISITES:

1) Install pg_bsd_indent in your PATH.  Its source code is in the
   sibling directory src/tools/pg_bsd_indent; see the directions
   in that directory's README file.

2) Install perltidy.  Please be sure it is version 20230309 (older and newer
   versions make different formatting choices, and we want consistency).
   You can get the correct version from
   https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/
   To install, follow the usual install process for a Perl module
   ("man perlmodinstall" explains it).  Or, if you have cpan installed,
   this should work:
   cpan SHANCOCK/Perl-Tidy-20230309.tar.gz
   Or if you have cpanm installed, you can just use:
   cpanm https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/Perl-Tidy-20230309.tar.gz


DOING THE INDENT RUN BEFORE A NORMAL COMMIT:

1) Change directory to the top of the source tree.

2) Run pgindent on the C files:

	src/tools/pgindent/pgindent .

   If any files generate errors, restore their original versions with
   "git checkout", and see below for cleanup ideas.

3) Check for any newly-created files using "git status"; there shouldn't
   be any.  (pgindent leaves *.BAK files behind if it has trouble, while
   perltidy leaves *.LOG files behind.)

4) If pgindent wants to change anything your commit wasn't touching,
   stop and figure out why.  If it is making ugly whitespace changes
   around typedefs your commit adds, you need to add those typedefs
   to src/tools/pgindent/typedefs.list.

5) If you have the patience, it's worth eyeballing the "git diff" output
   for any egregiously ugly changes.  See below for cleanup ideas.

6) Do a full test build:

	make -s clean
	make -s all	# look for unexpected warnings, and errors of course
	make check-world

   Your configure switches should include at least --enable-tap-tests
   or else much of the Perl code won't get exercised.
   The ecpg regression tests may well fail due to pgindent's updates of
   header files that get copied into ecpg output; if so, adjust the
   expected-files to match.


AT LEAST ONCE PER RELEASE CYCLE:

1) Download the latest typedef file from the buildfarm:

	wget -O src/tools/pgindent/typedefs.list https://buildfarm.postgresql.org/cgi-bin/typedefs.pl

   This step resolves any differences between the incrementally updated
   version of the file and a clean, autogenerated one.
   (See https://buildfarm.postgresql.org/cgi-bin/typedefs.pl?show_list for
   a full list of typedef files, if you want to indent some back branch.)

2) Run pgindent as above.

3) Indent the Perl code using perltidy:

	src/tools/pgindent/pgperltidy .

   If you want to use some perltidy version that's not in your PATH,
   first set the PERLTIDY environment variable to point to it.

4) Reformat the bootstrap catalog data files:

	./configure     # "make" will not work in an unconfigured tree
	cd src/include/catalog
	make reformat-dat-files
	cd ../../..

5) When you're done, "git commit" everything including the typedefs.list file
   you used.

6) Add the newly created commit(s) to the .git-blame-ignore-revs file so
   that "git blame" ignores the commits (for anybody that has opted-in
   to using the ignore file).  Follow the instructions that appear at
   the top of the .git-blame-ignore-revs file.

Another "git commit" will be required for your ignore file changes.

---------------------------------------------------------------------------

Cleaning up in case of failure or ugly output
---------------------------------------------

If you don't like the results for any particular file, "git checkout"
that file to undo the changes, patch the file as needed, then repeat
the indent process.

pgindent will reflow any comment block that's not at the left margin.
If this messes up manual formatting that ought to be preserved, protect
the comment block with some dashes:

	/*----------
	 * Text here will not be touched by pgindent.
	 */

Odd spacing around typedef names might indicate an incomplete typedefs list.

pgindent will mangle both declaration and definition of a C function whose
name matches a typedef.  Currently the best workaround is to choose
non-conflicting names.

pgindent can get confused by #if sequences that look correct to the compiler
but have mismatched braces/parentheses when considered as a whole.  Usually
that looks pretty unreadable to humans too, so best practice is to rearrange
the #if tests to avoid it.

Sometimes, if pgindent or perltidy produces odd-looking output, it's because
of minor bugs like extra commas.  Don't hesitate to clean that up while
you're at it.

---------------------------------------------------------------------------

BSD indent
----------

We have standardized on FreeBSD's indent, and renamed it pg_bsd_indent.
pg_bsd_indent does differ slightly from FreeBSD's version, mostly in
being more easily portable to non-BSD platforms.  Find it in the
sibling directory src/tools/pg_bsd_indent.

GNU indent, version 2.2.6, has several problems, and is not recommended.
These bugs become pretty major when you are doing >500k lines of code.
If you don't believe me, take a directory and make a copy.  Run pgindent
on the copy using GNU indent, and do a diff -r. You will see what I
mean. GNU indent does some things better, but mangles too.  For details,
see:

	http://archives.postgresql.org/pgsql-hackers/2003-10/msg00374.php
	http://archives.postgresql.org/pgsql-hackers/2011-04/msg01436.php

---------------------------------------------------------------------------

Which files are processed
-------------------------

The pgindent run processes (nearly) all PostgreSQL *.c and *.h files,
but we currently exclude *.y and *.l files, as well as *.c and *.h files
derived from *.y and *.l files.  Additional exceptions are listed
in exclude_file_patterns; see the notes therein for rationale.

Note that we do not exclude ecpg's header files from the run.  Some of them
get copied verbatim into ecpg's output, meaning that ecpg's expected files
may need to be updated to match.

The perltidy run processes all *.pl and *.pm files, plus a few
executable Perl scripts that are not named that way.  See the "find"
rules in pgperltidy for details.