postgres.git / summary / log / commit / refs
commit 9dbc53591a2de03e0cfdab61a78726f8b2c29eef
Author: Peter Eisentraut <peter@eisentraut.org>
Date: Mon Oct 05 11:17:43 2026 +0000
pgindent: Skip build directories automatically
pgindent descended into build directories located inside the source
tree and reindented the generated files there, which is wasteful and
often makes pg_bsd_indent fail outright. This change automatically
recognizes build directories and skips them. This works for both
Meson build directories and Autoconf VPATH build directories. A build
directory named directly on the command line is still processed, on
the assumption that this was asked for on purpose.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/fc77b35a-34c4-4229-82f1-8cf0ce67f276%40eisentraut.org
src/tools/pgindent/pgindent | 32 ++++++++++++++++++++++++++++++--
src/tools/pgindent/pgindent.man | 5 +++++
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index ee30da799b4..fa2041dc34b 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -209,6 +209,20 @@ sub process_exclude
return;
}
+# Does the given directory look like the top of a build tree?
+sub is_build_dir
+{
+ my $dir = shift;
+
+ # This is how Meson itself identifies a build tree.
+ return 1 if -f "$dir/meson-private/coredata.dat";
+
+ # Autoconf VPATH build directory
+ return 1 if -f "$dir/config.status" && !-f "$dir/configure.ac";
+
+ return 0;
+}
+
sub read_source
{
my $source_filename = shift;
@@ -467,8 +481,22 @@ check_indent();
my $wanted = sub {
my ($dev, $ino, $mode, $nlink, $uid, $gid);
- (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))
- && -f _
+ return unless (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_));
+
+ # Don't even descend into a build tree.
+ #
+ # Note that File::Find has chdir'd into the containing directory,
+ # so $_ is what we must test. For a directory named on the
+ # command line, $_ is ".", and we process such a directory even if
+ # it is a build tree, since that was asked for explicitly.
+ if (-d _)
+ {
+ $File::Find::prune = 1
+ if ($_ ne "." && is_build_dir($_));
+ return;
+ }
+
+ -f _
&& /^.*\.[ch]\z/s
&& push(@files, $File::Find::name);
};
diff --git a/src/tools/pgindent/pgindent.man b/src/tools/pgindent/pgindent.man
index caab5cde914..358ba096447 100644
--- a/src/tools/pgindent/pgindent.man
+++ b/src/tools/pgindent/pgindent.man
@@ -31,6 +31,11 @@ find the file src/tools/pgindent/exclude_file_patterns. The --excludes option
can be used more than once to specify multiple files containing exclusion
patterns.
+Build directories that pgindent comes across while scanning a
+directory are recognized and skipped automatically. A build directory
+named directly on the command line is still processed, on the
+assumption that this was asked for on purpose.
+
There are also two non-destructive modes of pgindent. If given the --diff
option pgindent will show the changes it would make, but doesn't actually make
them. If given instead the --check option, pgindent will exit with a status of
[parent: a846ee9854ee]