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

..08-Nov-2021-

READMEH A D08-Nov-20215 KiB14797

exclude_file_patternsH A D08-Nov-2021161 76

indent.bsd.patchH A D08-Nov-20217.1 KiB289271

perltidyrcH A D08-Nov-2021301 1312

pgcppindentH A D08-Nov-2021690 3024

pgindentH A D08-Nov-202113.2 KiB565346

pgindent.manH A D08-Nov-20212 KiB4532

pgperltidyH A D08-Nov-2021593 2411

typedefs.listH A D08-Nov-202143.6 KiB2,9602,959

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 (see below for details).
14
152) Install entab (src/tools/entab/).
16
173) Install perltidy.  Please be sure it is v20090616 (older and newer
18   versions make different formatting choices, and we want consistency).
19
20DOING THE INDENT RUN:
21
221) Change directory to the top of the source tree.
23
242) Remove all derived files (pgindent has trouble with flex files, and it
25   would be pointless to run it on them anyway):
26
27	make maintainer-clean
28   Or:
29	git clean -fdx
30
313) Download the latest typedef file from the buildfarm:
32
33	wget -O src/tools/pgindent/typedefs.list https://buildfarm.postgresql.org/cgi-bin/typedefs.pl
34
35   (See https://www.pgbuildfarm.org/cgi-bin/typedefs.pl?show_list for a full
36   list of typedef files, if you want to indent some back branch.)
37
384) Run pgindent on the C files:
39
40	src/tools/pgindent/pgindent
41
42   If any files generate errors, restore their original versions with
43   "git checkout", and see below for cleanup ideas.
44
455) Indent the Perl code using perltidy:
46
47	src/tools/pgindent/pgperltidy
48
49   If you want to use some perltidy version that's not in your PATH,
50   first set the PERLTIDY environment variable to point to it.
51
52VALIDATION:
53
541) Check for any newly-created files using "git status"; there shouldn't
55   be any.  (perltidy tends to leave *.LOG files behind if it has trouble.)
56
572) Do a full test build:
58
59	./configure ...
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
663) If you have the patience, it's worth eyeballing the "git diff" output
67   for any egregiously ugly changes.  See below for cleanup ideas.
68
69
70When you're done, "git commit" everything including the typedefs.list file
71you used.
72
73
74---------------------------------------------------------------------------
75
76Cleaning up in case of failure or ugly output
77---------------------------------------------
78
79If you don't like the results for any particular file, "git checkout"
80that file to undo the changes, patch the file as needed, then repeat
81the indent process.
82
83pgindent will reflow any comment block that's not at the left margin.
84If this messes up manual formatting that ought to be preserved, protect
85the comment block with some dashes:
86
87	/*----------
88	 * Text here will not be touched by pgindent.
89	 *----------
90	 */
91
92Odd spacing around typedef names might indicate an incomplete typedefs list.
93
94pgindent can get confused by #if sequences that look correct to the compiler
95but have mismatched braces/parentheses when considered as a whole.  Usually
96that looks pretty unreadable to humans too, so best practice is to rearrange
97the #if tests to avoid it.
98
99Sometimes, if pgindent or perltidy produces odd-looking output, it's because
100of minor bugs like extra commas.  Don't hesitate to clean that up while
101you're at it.
102
103---------------------------------------------------------------------------
104
105BSD indent
106----------
107
108We have standardized on NetBSD's indent, and renamed it pg_bsd_indent.
109We have fixed a few bugs which requre the NetBSD source to be patched
110with indent.bsd.patch patch.  A fully patched version is available at
111https://ftp.postgresql.org/pub/dev.
112
113GNU indent, version 2.2.6, has several problems, and is not recommended.
114These bugs become pretty major when you are doing >500k lines of code.
115If you don't believe me, take a directory and make a copy.  Run pgindent
116on the copy using GNU indent, and do a diff -r. You will see what I
117mean. GNU indent does some things better, but mangles too.  For details,
118see:
119
120	http://archives.postgresql.org/pgsql-hackers/2003-10/msg00374.php
121	http://archives.postgresql.org/pgsql-hackers/2011-04/msg01436.php
122
123---------------------------------------------------------------------------
124
125Which files are processed
126-------------------------
127
128The pgindent run processes (nearly) all PostgreSQL *.c and *.h files,
129but we currently exclude *.y and *.l files.  Exceptions are listed
130in exclude_file_patterns:
131
132src/include/storage/s_lock.h and src/include/port/atomics/ are excluded
133because they contain assembly code that pgindent tends to mess up.
134
135src/interfaces/ecpg/test/expected/ is excluded to avoid breaking the ecpg
136regression tests.  Several *.h files are included in regression output so
137should not be changed.
138
139src/include/snowball/libstemmer/ and src/backend/snowball/libstemmer/
140are excluded because those files are imported from an external project,
141not maintained locally, and are machine-generated anyway.  Likewise for
142plperl/ppport.h.
143
144The perltidy run processes all *.pl and *.pm files, plus a few
145executable Perl scripts that are not named that way.  See the "find"
146rules in pgperltidy for details.
147