From b2b690df0207e887722166b2796676cf93dd1ff0 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 24 Sep 2026 16:03:14 +0200 Subject: [PATCH 3/3] 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. The --exclude-dir option added by the previous commit can take care of that, but it has to be spelled out on every invocation, and the names of the build directories are a local choice that pgindent cannot guess. This change automatically recognizes build directories and skips them. Meson build directories are identified by the presence of meson-private/coredata.dat, which is the same test Meson itself uses; Autoconf build directories created outside the source tree are identified by config.status without configure.ac. A build directory named directly on the command line is still processed, on the assumption that this was asked for on purpose. --- src/tools/pgindent/pgindent | 27 +++++++++++++++++++++++---- src/tools/pgindent/pgindent.man | 8 ++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent index cbfa50fadb0..fceeeeb2559 100755 --- a/src/tools/pgindent/pgindent +++ b/src/tools/pgindent/pgindent @@ -243,6 +243,20 @@ sub in_excluded_dir return 0; } +# Does the given directory look like the top of a build tree? +sub is_build_dir +{ + my $dir = shift; + + # This is how Meson itself identifiers 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; @@ -481,11 +495,16 @@ my $wanted = sub { my ($dev, $ino, $mode, $nlink, $uid, $gid); return unless (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_)); - # Don't even descend into an excluded directory. Note that File::Find - # has chdir'd into the containing directory, so $_ is what we must test. - if (-d _ && in_excluded_dir($_)) + # Don't even descend into an excluded directory, nor 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; + $File::Find::prune = 1 + if in_excluded_dir($_) || ($_ ne "." && is_build_dir($_)); return; } diff --git a/src/tools/pgindent/pgindent.man b/src/tools/pgindent/pgindent.man index cac2d30cd41..6e6d193561d 100644 --- a/src/tools/pgindent/pgindent.man +++ b/src/tools/pgindent/pgindent.man @@ -40,6 +40,14 @@ example: Relative directory names are interpreted relative to the directory pgindent is invoked in. This option can also be used more than once. +Build directories that pgindent comes across while scanning a +directory are recognized and skipped automatically, so they usually +don't need to be listed with --exclude-dir. This works for Meson +build directories and for Autoconf build directories created outside +the source tree. 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 -- 2.55.0