From 2548968374909e3ea7ca914e73f5e50528cae5a7 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 1 Oct 2026 09:01:35 +0200 Subject: [PATCH v2] 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. 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 eea6c0ad734..f6483d68be8 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; @@ -440,8 +454,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 base-commit: 45277ca0d1cb6dbe722a01b3b5461c30abd40eee -- 2.55.0