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