summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2023-02-13 08:13:03 -0500
committerAndrew Dunstan <andrew@dunslane.net>2023-02-13 08:24:54 -0500
commitb16259b3c1897cf90855a94e5cb126d6c75e3cf3 (patch)
tree66d350730659499a55048bf2c67060e0f1d66852 /src/tools
parent9a312562314abcec91ae9cff3a4af37196c3886e (diff)
downloadpostgresql-b16259b3c1897cf90855a94e5cb126d6c75e3cf3.tar.gz
Remove obsolete pgindent options --code-base and --build
Now that we have the sources for pg_bsd_indent in our code base these are redundant. It is now required to provide a list of files or directories to pgindent, either by using --commit or on the command line. The equivalent of previously running pgindent with no parameters is now `pgindent .` Some extra checks are also added. duplicate files in the file list are skipped, and there is a warning if no files are specified. If the --commit option is used, the script now chdir's to the source root, as git always reports files relative to that. (Fixes a gripe from Justin Pryzby) Reviewed by Tom Lane Discussion: https://postgr.es/m/842819.1676219054@sss.pgh.pa.us
Diffstat (limited to 'src/tools')
-rwxr-xr-xsrc/tools/pgindent/pgindent101
-rw-r--r--src/tools/pgindent/pgindent.man12
2 files changed, 14 insertions, 99 deletions
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index a793971e07..8a2d39c4f6 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -21,7 +21,7 @@ my $indent_opts =
my $devnull = File::Spec->devnull;
-my ($typedefs_file, $typedef_str, $code_base,
+my ($typedefs_file, $typedef_str,
@excludes, $indent, $build,
$show_diff, $silent_diff, $help,
@commits,);
@@ -33,10 +33,8 @@ my %options = (
"commit=s" => \@commits,
"typedefs=s" => \$typedefs_file,
"list-of-typedefs=s" => \$typedef_str,
- "code-base=s" => \$code_base,
"excludes=s" => \@excludes,
"indent=s" => \$indent,
- "build" => \$build,
"show-diff" => \$show_diff,
"silent-diff" => \$silent_diff,);
GetOptions(%options) || usage("bad command line argument");
@@ -46,22 +44,16 @@ usage() if $help;
usage("Cannot have both --silent-diff and --show-diff")
if $silent_diff && $show_diff;
-usage("Cannot use --commit with --code-base or command line file list")
- if (@commits && ($code_base || @ARGV));
+usage("Cannot use --commit with command line file list")
+ if (@commits && @ARGV);
-run_build($code_base) if ($build);
-
-# command line option wins, then environment (which is how --build sets it) ,
-# then locations. based on current dir, then default location
+# command line option wins, then environment, then locations based on current
+# dir, then default location
$typedefs_file ||= $ENV{PGTYPEDEFS};
-# build mode sets PGINDENT
+# get indent location for environment or default
$indent ||= $ENV{PGINDENT} || $ENV{INDENT} || "pg_bsd_indent";
-# if no non-option arguments or commits are given, default to looking in the
-# current directory
-$code_base ||= '.' unless (@ARGV || @commits);
-
my $sourcedir = locate_sourcedir();
# if it's the base of a postgres tree, we will exclude the files
@@ -121,8 +113,7 @@ sub check_indent
sub locate_sourcedir
{
# try fairly hard to locate the sourcedir
- my $where = $code_base || '.';
- my $sub = "$where/src/tools/pgindent";
+ my $sub = "./src/tools/pgindent";
return $sub if -d $sub;
# try to find it from an ancestor directory
$sub = "../src/tools/pgindent";
@@ -320,72 +311,6 @@ sub show_diff
return $diff;
}
-sub run_build
-{
- eval "use LWP::Simple;"; ## no critic (ProhibitStringyEval);
-
- my $code_base = shift || '.';
- my $save_dir = getcwd();
-
- # look for the code root
- foreach (1 .. 5)
- {
- last if -d "$code_base/src/tools/pgindent";
- $code_base = "$code_base/..";
- }
-
- die "cannot locate src/tools/pgindent directory in \"$code_base\"\n"
- unless -d "$code_base/src/tools/pgindent";
-
- chdir "$code_base/src/tools/pgindent";
-
- my $typedefs_list_url =
- "https://buildfarm.postgresql.org/cgi-bin/typedefs.pl";
-
- my $rv = getstore($typedefs_list_url, "tmp_typedefs.list");
-
- die "cannot fetch typedefs list from $typedefs_list_url\n"
- unless is_success($rv);
-
- $ENV{PGTYPEDEFS} = abs_path('tmp_typedefs.list');
-
- my $indentrepo = "https://git.postgresql.org/git/pg_bsd_indent.git";
- system("git clone $indentrepo >$devnull 2>&1");
- die "could not fetch pg_bsd_indent sources from $indentrepo\n"
- unless $? == 0;
-
- chdir "pg_bsd_indent" || die;
- system("make all check >$devnull");
- die "could not build pg_bsd_indent from source\n"
- unless $? == 0;
-
- $ENV{PGINDENT} = abs_path('pg_bsd_indent');
-
- chdir $save_dir;
- return;
-}
-
-sub build_clean
-{
- my $code_base = shift || '.';
-
- # look for the code root
- foreach (1 .. 5)
- {
- last if -d "$code_base/src/tools/pgindent";
- $code_base = "$code_base/..";
- }
-
- die "cannot locate src/tools/pgindent directory in \"$code_base\"\n"
- unless -d "$code_base/src/tools/pgindent";
-
- chdir "$code_base";
-
- system("rm -rf src/tools/pgindent/pg_bsd_indent");
- system("rm -f src/tools/pgindent/tmp_typedefs.list");
- return;
-}
-
sub usage
{
my $message = shift;
@@ -397,10 +322,8 @@ Options:
--commit=gitref use files modified by the named commit
--typedefs=FILE file containing a list of typedefs
--list-of-typedefs=STR string containing typedefs, space separated
- --code-base=DIR path to the base of PostgreSQL source code
--excludes=PATH file containing list of filename patterns to ignore
--indent=PATH path to pg_bsd_indent program
- --build build the pg_bsd_indent program
--show-diff show the changes that would be made
--silent-diff exit with status 2 if any changes would be made
The --excludes and --commit options can be given more than once.
@@ -423,8 +346,6 @@ $filtered_typedefs_fh = load_typedefs();
check_indent();
-build_clean($code_base) if $build;
-
my $wanted = sub
{
my ($dev, $ino, $mode, $nlink, $uid, $gid);
@@ -434,12 +355,12 @@ my $wanted = sub
&& push(@files, $File::Find::name);
};
-# get the list of files under code base, if it's set
-File::Find::find({wanted => $wanted }, $code_base) if $code_base;
-
# any non-option arguments are files or directories to be processed
File::Find::find({wanted => $wanted}, @ARGV) if @ARGV;
+# commit file locations are relative to the source root
+chdir "$sourcedir/../../.." if @commits && $sourcedir;
+
# process named commits by comparing each with their immediate ancestor
foreach my $commit (@commits)
{
@@ -450,6 +371,8 @@ foreach my $commit (@commits)
push(@files,@affected);
}
+warn "No files to process" unless @files;
+
# remove excluded files from the file list
process_exclude();
diff --git a/src/tools/pgindent/pgindent.man b/src/tools/pgindent/pgindent.man
index 7406794ba3..fe411ee699 100644
--- a/src/tools/pgindent/pgindent.man
+++ b/src/tools/pgindent/pgindent.man
@@ -8,14 +8,9 @@ You can see all the options by running:
pgindent --help
In its simplest form, if all the required objects are installed, simply run
-it without any parameters at the top of the source tree you want to process.
+it at the top of the source tree you want to process like this:
- pgindent
-
-If you don't have all the requirements installed, pgindent will fetch and build
-them for you, if you're in a PostgreSQL source tree:
-
- pgindent --build
+ pgindent .
If your pg_bsd_indent program is not installed in your path, you can specify
it by setting the environment variable INDENT, or PGINDENT, or by giving the
@@ -28,9 +23,6 @@ specified using the PGTYPEDEFS environment variable, or via the command line
--typedefs option. If neither is used, it will look for it within the
current source tree, or in /usr/local/etc/typedefs.list.
-If you want to indent a source tree other than the current working directory,
-you can specify it via the --code-base command line option.
-
We don't want to indent certain files in the PostgreSQL source. pgindent
will honor a file containing a list of patterns of files to avoid. This
file can be specified using the --excludes command line option. If indenting