1
- pgindent
2
- ========
1
+ pgindent'ing the PostgreSQL source tree
2
+ =======================================
3
3
4
- This can format all PostgreSQL *.c and *.h files, but excludes *.y, and
5
- *.l files .
4
+ We run this process at least once in each development cycle,
5
+ to maintain uniform layout style in our C and Perl code .
6
6
7
- 1) Install pg_bsd_indent (see below for details).
7
+ You might find this blog post interesting:
8
+ http://adpgtech.blogspot.com/2015/05/running-pgindent-on-non-core-code-or.html
9
+
10
+
11
+ PREREQUISITES:
12
+
13
+ 1) Install pg_bsd_indent in your PATH (see below for details).
8
14
9
15
2) Install entab (src/tools/entab/).
10
16
11
- 3) Change directory to the top of the build tree.
17
+ 3) Install perltidy. Please be sure it is v20090616 (older and newer
18
+ versions make different formatting choices, and we want consistency).
12
19
13
- 4) Remove all derived files (pgindent has trouble with one of the flex macros) :
20
+ DOING THE INDENT RUN :
14
21
15
- make maintainer-clean
22
+ 1) Change directory to the top of the source tree.
16
23
17
- Or:
24
+ 2) Remove all derived files (pgindent has trouble with flex files, and it
25
+ would be pointless to run it on them anyway):
18
26
27
+ make maintainer-clean
28
+ Or:
19
29
git clean -fdx
20
30
21
- 5 ) Download the typedef file from the buildfarm:
31
+ 3 ) Download the latest typedef file from the buildfarm:
22
32
23
33
wget -O src/tools/pgindent/typedefs.list http://buildfarm.postgresql.org/cgi-bin/typedefs.pl
24
34
25
- (see http://www.pgbuildfarm.org/cgi-bin/typedefs.pl?show_list for a full list of typedefs,
26
- also http://adpgtech.blogspot.com/2015/05/running-pgindent-on-non-core-code-or.html )
35
+ (See http://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. )
27
37
28
- 6 ) Run pgindent:
38
+ 4 ) Run pgindent on the C files :
29
39
30
40
src/tools/pgindent/pgindent
31
41
32
- 7) Remove any files that generate errors and restore their original
33
- versions.
42
+ If any files generate errors, restore their original versions with
43
+ "git checkout", and see below for cleanup ideas.
44
+
45
+ 5) Indent the Perl code using perltidy:
46
+
47
+ src/tools/pgindent/pgperltidy
34
48
35
- 8) Indent the Perl code using perltidy v20090616 ( perltidy changes formatting
36
- decisions, so older and newer versions are incompatible):
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.
37
51
38
- (
39
- find . -name \*.pl -o -name \*.pm
52
+ VALIDATION:
40
53
41
- find . -type f -exec file {} \; |
42
- egrep -i ':.*perl[0-9]*\>' |
43
- cut -d: -f1
44
- ) |
45
- sort -u |
46
- xargs perltidy --profile=src/tools/pgindent/perltidyrc
54
+ 1) 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.)
47
56
48
- 9 ) Do a full test build:
57
+ 2 ) Do a full test build:
49
58
50
- > run configure
51
- # stop is only necessary if it's going to install in a location with an
52
- # already running server
53
- pg_ctl stop
54
- run configure
55
- make -C src install
56
- make -C contrib install
57
- run initdb
58
- pg_ctl start
59
- make installcheck-world
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
+
66
+ 3) 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
+
70
+ When you're done, "git commit" everything including the typedefs.list file
71
+ you used.
60
72
61
- 10) Remove Perl backup files after testing (*.bak)
73
+
74
+ ---------------------------------------------------------------------------
75
+
76
+ Cleaning up in case of failure or ugly output
77
+ ---------------------------------------------
78
+
79
+ If you don't like the results for any particular file, "git checkout"
80
+ that file to undo the changes, patch the file as needed, then repeat
81
+ the indent process.
82
+
83
+ pgindent will reflow any comment block that's not at the left margin.
84
+ If this messes up manual formatting that ought to be preserved, protect
85
+ the comment block with some dashes:
86
+
87
+ /*----------
88
+ * Text here will not be touched by pgindent.
89
+ *----------
90
+ */
91
+
92
+ Odd spacing around typedef names might indicate an incomplete typedefs list.
93
+
94
+ pgindent can get confused by #if sequences that look correct to the compiler
95
+ but have mismatched braces/parentheses when considered as a whole. Usually
96
+ that looks pretty unreadable to humans too, so best practice is to rearrange
97
+ the #if tests to avoid it.
98
+
99
+ Sometimes, if pgindent or perltidy produces odd-looking output, it's because
100
+ of minor bugs like extra commas. Don't hesitate to clean that up while
101
+ you're at it.
62
102
63
103
---------------------------------------------------------------------------
64
104
@@ -82,33 +122,25 @@ see:
82
122
83
123
---------------------------------------------------------------------------
84
124
85
- Notes about excluded files
86
- --------------------------
125
+ Which files are processed
126
+ -------------------------
127
+
128
+ The pgindent run processes (nearly) all PostgreSQL *.c and *.h files,
129
+ but we currently exclude *.y and *.l files. Exceptions are listed
130
+ in exclude_file_patterns:
87
131
88
132
src/include/storage/s_lock.h and src/include/port/atomics/ are excluded
89
133
because they contain assembly code that pgindent tends to mess up.
90
134
91
- src/include/snowball/libstemmer/ and src/backend/snowball/libstemmer/
92
- are excluded because those files are imported from an external project,
93
- not maintained locally, and are machine-generated anyway.
94
-
95
135
src/interfaces/ecpg/test/expected/ is excluded to avoid breaking the ecpg
96
136
regression tests. Several *.h files are included in regression output so
97
137
should not be changed.
98
138
99
- ---------------------------------------------------------------------------
100
-
101
- Obsolete typedef list creation instructions
102
- -------------------------------------------
103
-
104
- To use pgindent:
105
-
106
- 1) Build the source tree with _debug_ symbols and all possible configure options
107
-
108
- 2) Install to /usr/local/pgsql
109
-
110
- 3) Install all contrib modules
111
-
112
- 4) Save a list of typedefs by running:
139
+ src/include/snowball/libstemmer/ and src/backend/snowball/libstemmer/
140
+ are excluded because those files are imported from an external project,
141
+ not maintained locally, and are machine-generated anyway. Likewise for
142
+ plperl/ppport.h.
113
143
114
- src/tools/find_typedef /usr/local/pgsql/bin /usr/local/pgsql/lib > /tmp/pgtypedefs
144
+ The perltidy run processes all *.pl and *.pm files, plus a few
145
+ executable Perl scripts that are not named that way. See the "find"
146
+ rules in pgperltidy for details.
0 commit comments