mirror of
https://github.com/postgres/postgres.git
synced 2025-05-20 05:13:53 +03:00
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
This commit is contained in:
parent
9a31256231
commit
b16259b3c1
@ -21,7 +21,7 @@ my $indent_opts =
|
|||||||
|
|
||||||
my $devnull = File::Spec->devnull;
|
my $devnull = File::Spec->devnull;
|
||||||
|
|
||||||
my ($typedefs_file, $typedef_str, $code_base,
|
my ($typedefs_file, $typedef_str,
|
||||||
@excludes, $indent, $build,
|
@excludes, $indent, $build,
|
||||||
$show_diff, $silent_diff, $help,
|
$show_diff, $silent_diff, $help,
|
||||||
@commits,);
|
@commits,);
|
||||||
@ -33,10 +33,8 @@ my %options = (
|
|||||||
"commit=s" => \@commits,
|
"commit=s" => \@commits,
|
||||||
"typedefs=s" => \$typedefs_file,
|
"typedefs=s" => \$typedefs_file,
|
||||||
"list-of-typedefs=s" => \$typedef_str,
|
"list-of-typedefs=s" => \$typedef_str,
|
||||||
"code-base=s" => \$code_base,
|
|
||||||
"excludes=s" => \@excludes,
|
"excludes=s" => \@excludes,
|
||||||
"indent=s" => \$indent,
|
"indent=s" => \$indent,
|
||||||
"build" => \$build,
|
|
||||||
"show-diff" => \$show_diff,
|
"show-diff" => \$show_diff,
|
||||||
"silent-diff" => \$silent_diff,);
|
"silent-diff" => \$silent_diff,);
|
||||||
GetOptions(%options) || usage("bad command line argument");
|
GetOptions(%options) || usage("bad command line argument");
|
||||||
@ -46,22 +44,16 @@ usage() if $help;
|
|||||||
usage("Cannot have both --silent-diff and --show-diff")
|
usage("Cannot have both --silent-diff and --show-diff")
|
||||||
if $silent_diff && $show_diff;
|
if $silent_diff && $show_diff;
|
||||||
|
|
||||||
usage("Cannot use --commit with --code-base or command line file list")
|
usage("Cannot use --commit with command line file list")
|
||||||
if (@commits && ($code_base || @ARGV));
|
if (@commits && @ARGV);
|
||||||
|
|
||||||
run_build($code_base) if ($build);
|
# command line option wins, then environment, then locations based on current
|
||||||
|
# dir, then default location
|
||||||
# command line option wins, then environment (which is how --build sets it) ,
|
|
||||||
# then locations. based on current dir, then default location
|
|
||||||
$typedefs_file ||= $ENV{PGTYPEDEFS};
|
$typedefs_file ||= $ENV{PGTYPEDEFS};
|
||||||
|
|
||||||
# build mode sets PGINDENT
|
# get indent location for environment or default
|
||||||
$indent ||= $ENV{PGINDENT} || $ENV{INDENT} || "pg_bsd_indent";
|
$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();
|
my $sourcedir = locate_sourcedir();
|
||||||
|
|
||||||
# if it's the base of a postgres tree, we will exclude the files
|
# if it's the base of a postgres tree, we will exclude the files
|
||||||
@ -121,8 +113,7 @@ sub check_indent
|
|||||||
sub locate_sourcedir
|
sub locate_sourcedir
|
||||||
{
|
{
|
||||||
# try fairly hard to locate the sourcedir
|
# try fairly hard to locate the sourcedir
|
||||||
my $where = $code_base || '.';
|
my $sub = "./src/tools/pgindent";
|
||||||
my $sub = "$where/src/tools/pgindent";
|
|
||||||
return $sub if -d $sub;
|
return $sub if -d $sub;
|
||||||
# try to find it from an ancestor directory
|
# try to find it from an ancestor directory
|
||||||
$sub = "../src/tools/pgindent";
|
$sub = "../src/tools/pgindent";
|
||||||
@ -320,72 +311,6 @@ sub show_diff
|
|||||||
return $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
|
sub usage
|
||||||
{
|
{
|
||||||
my $message = shift;
|
my $message = shift;
|
||||||
@ -397,10 +322,8 @@ Options:
|
|||||||
--commit=gitref use files modified by the named commit
|
--commit=gitref use files modified by the named commit
|
||||||
--typedefs=FILE file containing a list of typedefs
|
--typedefs=FILE file containing a list of typedefs
|
||||||
--list-of-typedefs=STR string containing typedefs, space separated
|
--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
|
--excludes=PATH file containing list of filename patterns to ignore
|
||||||
--indent=PATH path to pg_bsd_indent program
|
--indent=PATH path to pg_bsd_indent program
|
||||||
--build build the pg_bsd_indent program
|
|
||||||
--show-diff show the changes that would be made
|
--show-diff show the changes that would be made
|
||||||
--silent-diff exit with status 2 if any changes 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.
|
The --excludes and --commit options can be given more than once.
|
||||||
@ -423,8 +346,6 @@ $filtered_typedefs_fh = load_typedefs();
|
|||||||
|
|
||||||
check_indent();
|
check_indent();
|
||||||
|
|
||||||
build_clean($code_base) if $build;
|
|
||||||
|
|
||||||
my $wanted = sub
|
my $wanted = sub
|
||||||
{
|
{
|
||||||
my ($dev, $ino, $mode, $nlink, $uid, $gid);
|
my ($dev, $ino, $mode, $nlink, $uid, $gid);
|
||||||
@ -434,12 +355,12 @@ my $wanted = sub
|
|||||||
&& push(@files, $File::Find::name);
|
&& 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
|
# any non-option arguments are files or directories to be processed
|
||||||
File::Find::find({wanted => $wanted}, @ARGV) if @ARGV;
|
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
|
# process named commits by comparing each with their immediate ancestor
|
||||||
foreach my $commit (@commits)
|
foreach my $commit (@commits)
|
||||||
{
|
{
|
||||||
@ -450,6 +371,8 @@ foreach my $commit (@commits)
|
|||||||
push(@files,@affected);
|
push(@files,@affected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warn "No files to process" unless @files;
|
||||||
|
|
||||||
# remove excluded files from the file list
|
# remove excluded files from the file list
|
||||||
process_exclude();
|
process_exclude();
|
||||||
|
|
||||||
|
@ -8,14 +8,9 @@ You can see all the options by running:
|
|||||||
pgindent --help
|
pgindent --help
|
||||||
|
|
||||||
In its simplest form, if all the required objects are installed, simply run
|
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
|
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
|
|
||||||
|
|
||||||
If your pg_bsd_indent program is not installed in your path, you can specify
|
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
|
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
|
--typedefs option. If neither is used, it will look for it within the
|
||||||
current source tree, or in /usr/local/etc/typedefs.list.
|
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
|
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
|
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
|
file can be specified using the --excludes command line option. If indenting
|
||||||
|
Loading…
x
Reference in New Issue
Block a user