1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

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
This commit is contained in:
Peter Eisentraut
2026-10-05 13:17:43 +02:00
parent a846ee9854
commit 9dbc53591a
2 changed files with 35 additions and 2 deletions

View File

@@ -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);
};

View File

@@ -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