• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..08-Nov-2021-

READMEH A D08-Nov-20215.8 KiB157108

exclude_file_patternsH A D08-Nov-2021210 98

perltidyrcH A D08-Nov-2021416 1716

pgindentH A D08-Nov-202110.5 KiB450284

pgindent.manH A D08-Nov-20211.9 KiB4130

pgperltidyH A D08-Nov-2021246 134

typedefs.listH A D08-Nov-202150.8 KiB3,3613,360

README

1pgindent'ing the PostgreSQL source tree
2=======================================
3
4We run this process at least once in each development cycle,
5to maintain uniform layout style in our C and Perl code.
6
7You might find this blog post interesting:
8http://adpgtech.blogspot.com/2015/05/running-pgindent-on-non-core-code-or.html
9
10
11PREREQUISITES:
12
131) Install pg_bsd_indent in your PATH.  Fetch its source code with
14   git clone https://git.postgresql.org/git/pg_bsd_indent.git
15   then follow the directions in README.pg_bsd_indent therein.
16
172) Install perltidy.  Please be sure it is version 20170521 (older and newer
18   versions make different formatting choices, and we want consistency).
19   You can get the correct version from
20   https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/
21   To install, follow the usual install process for a Perl module
22   ("man perlmodinstall" explains it).  Or, if you have cpan installed,
23   this should work:
24   cpan SHANCOCK/Perl-Tidy-20170521.tar.gz
25
26DOING THE INDENT RUN:
27
281) Change directory to the top of the source tree.
29
302) Download the latest typedef file from the buildfarm:
31
32	wget -O src/tools/pgindent/typedefs.list https://buildfarm.postgresql.org/cgi-bin/typedefs.pl
33
34   (See https://www.pgbuildfarm.org/cgi-bin/typedefs.pl?show_list for a full
35   list of typedef files, if you want to indent some back branch.)
36
373) Run pgindent on the C files:
38
39	src/tools/pgindent/pgindent
40
41   If any files generate errors, restore their original versions with
42   "git checkout", and see below for cleanup ideas.
43
444) Indent the Perl code using perltidy:
45
46	src/tools/pgindent/pgperltidy
47
48   If you want to use some perltidy version that's not in your PATH,
49   first set the PERLTIDY environment variable to point to it.
50
51VALIDATION:
52
531) Check for any newly-created files using "git status"; there shouldn't
54   be any.  (pgindent leaves *.BAK files behind if it has trouble, while
55   perltidy leaves *.LOG files behind.)
56
572) Do a full test build:
58
59	make -s clean
60	make -s all	# look for unexpected warnings, and errors of course
61	make check-world
62
63   Your configure switches should include at least --enable-tap-tests
64   or else much of the Perl code won't get exercised.
65   The ecpg regression tests may well fail due to pgindent's updates of
66   header files that get copied into ecpg output; if so, adjust the
67   expected-files to match.
68
693) If you have the patience, it's worth eyeballing the "git diff" output
70   for any egregiously ugly changes.  See below for cleanup ideas.
71
72
73When you're done, "git commit" everything including the typedefs.list file
74you used.
75
76
77---------------------------------------------------------------------------
78
79Cleaning up in case of failure or ugly output
80---------------------------------------------
81
82If you don't like the results for any particular file, "git checkout"
83that file to undo the changes, patch the file as needed, then repeat
84the indent process.
85
86pgindent will reflow any comment block that's not at the left margin.
87If this messes up manual formatting that ought to be preserved, protect
88the comment block with some dashes:
89
90	/*----------
91	 * Text here will not be touched by pgindent.
92	 *----------
93	 */
94
95Odd spacing around typedef names might indicate an incomplete typedefs list.
96
97pgindent can get confused by #if sequences that look correct to the compiler
98but have mismatched braces/parentheses when considered as a whole.  Usually
99that looks pretty unreadable to humans too, so best practice is to rearrange
100the #if tests to avoid it.
101
102Sometimes, if pgindent or perltidy produces odd-looking output, it's because
103of minor bugs like extra commas.  Don't hesitate to clean that up while
104you're at it.
105
106---------------------------------------------------------------------------
107
108BSD indent
109----------
110
111We have standardized on FreeBSD's indent, and renamed it pg_bsd_indent.
112pg_bsd_indent does differ slightly from FreeBSD's version, mostly in
113being more easily portable to non-BSD platforms.  You can obtain it from
114https://git.postgresql.org/git/pg_bsd_indent.git
115
116GNU indent, version 2.2.6, has several problems, and is not recommended.
117These bugs become pretty major when you are doing >500k lines of code.
118If you don't believe me, take a directory and make a copy.  Run pgindent
119on the copy using GNU indent, and do a diff -r. You will see what I
120mean. GNU indent does some things better, but mangles too.  For details,
121see:
122
123	http://archives.postgresql.org/pgsql-hackers/2003-10/msg00374.php
124	http://archives.postgresql.org/pgsql-hackers/2011-04/msg01436.php
125
126---------------------------------------------------------------------------
127
128Which files are processed
129-------------------------
130
131The pgindent run processes (nearly) all PostgreSQL *.c and *.h files,
132but we currently exclude *.y and *.l files, as well as *.c and *.h files
133derived from *.y and *.l files.  Additional exceptions are listed
134in exclude_file_patterns:
135
136src/include/storage/s_lock.h and src/include/port/atomics/ are excluded
137because they contain assembly code that pgindent tends to mess up.
138
139src/backend/utils/fmgrtab.c is excluded because it confuses pgindent
140and it's a derived file anyway.
141
142src/interfaces/ecpg/test/expected/ is excluded to avoid breaking the ecpg
143regression tests, since what ecpg generates is not necessarily formatted
144as pgindent would do it.  (Note that we do not exclude ecpg's header files
145from the run; some of them get copied verbatim into ecpg's output, meaning
146that the expected files may need to be updated to match.)
147
148src/include/snowball/libstemmer/ and src/backend/snowball/libstemmer/
149are excluded because those files are imported from an external project,
150not maintained locally, and are machine-generated anyway.  Likewise for
151plperl/ppport.h.
152
153
154The perltidy run processes all *.pl and *.pm files, plus a few
155executable Perl scripts that are not named that way.  See the "find"
156rules in pgperltidy for details.
157