mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Rename pgindent options
--show-diff becomes --diff, and --silent-diff becomes --check. These options may now be given together. Without --check, --diff will exit with a zero status even if diffs are found. With --check, it will now exit with a non-zero status in that case. Author: Tristan Partin Reviewed-by: Daniel Gustafsson, Jelte Fennema-Nio Discussion: https://postgr.es/m/CXLX2XYTH9S6.140SC6Y61VD88@neon.tech
This commit is contained in:
@ -22,8 +22,8 @@ my $indent_opts =
|
|||||||
my $devnull = File::Spec->devnull;
|
my $devnull = File::Spec->devnull;
|
||||||
|
|
||||||
my ($typedefs_file, $typedef_str, @excludes,
|
my ($typedefs_file, $typedef_str, @excludes,
|
||||||
$indent, $build, $show_diff,
|
$indent, $build, $diff,
|
||||||
$silent_diff, $help, @commits,);
|
$check, $help, @commits,);
|
||||||
|
|
||||||
$help = 0;
|
$help = 0;
|
||||||
|
|
||||||
@ -34,15 +34,12 @@ my %options = (
|
|||||||
"list-of-typedefs=s" => \$typedef_str,
|
"list-of-typedefs=s" => \$typedef_str,
|
||||||
"excludes=s" => \@excludes,
|
"excludes=s" => \@excludes,
|
||||||
"indent=s" => \$indent,
|
"indent=s" => \$indent,
|
||||||
"show-diff" => \$show_diff,
|
"diff" => \$diff,
|
||||||
"silent-diff" => \$silent_diff,);
|
"check" => \$check,);
|
||||||
GetOptions(%options) || usage("bad command line argument");
|
GetOptions(%options) || usage("bad command line argument");
|
||||||
|
|
||||||
usage() if $help;
|
usage() if $help;
|
||||||
|
|
||||||
usage("Cannot have both --silent-diff and --show-diff")
|
|
||||||
if $silent_diff && $show_diff;
|
|
||||||
|
|
||||||
usage("Cannot use --commit with command line file list")
|
usage("Cannot use --commit with command line file list")
|
||||||
if (@commits && @ARGV);
|
if (@commits && @ARGV);
|
||||||
|
|
||||||
@ -294,7 +291,7 @@ sub run_indent
|
|||||||
return $source;
|
return $source;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub show_diff
|
sub diff
|
||||||
{
|
{
|
||||||
my $indented = shift;
|
my $indented = shift;
|
||||||
my $source_filename = shift;
|
my $source_filename = shift;
|
||||||
@ -323,8 +320,8 @@ Options:
|
|||||||
--list-of-typedefs=STR string containing typedefs, space separated
|
--list-of-typedefs=STR string containing typedefs, space separated
|
||||||
--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
|
||||||
--show-diff show the changes that would be made
|
--diff show the changes that would be made
|
||||||
--silent-diff exit with status 2 if any changes would be made
|
--check 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.
|
||||||
EOF
|
EOF
|
||||||
if ($help)
|
if ($help)
|
||||||
@ -375,6 +372,7 @@ warn "No files to process" unless @files;
|
|||||||
process_exclude();
|
process_exclude();
|
||||||
|
|
||||||
my %processed;
|
my %processed;
|
||||||
|
my $status = 0;
|
||||||
|
|
||||||
foreach my $source_filename (@files)
|
foreach my $source_filename (@files)
|
||||||
{
|
{
|
||||||
@ -417,19 +415,24 @@ foreach my $source_filename (@files)
|
|||||||
|
|
||||||
if ($source ne $orig_source)
|
if ($source ne $orig_source)
|
||||||
{
|
{
|
||||||
if ($silent_diff)
|
if (!$diff && !$check)
|
||||||
{
|
{
|
||||||
exit 2;
|
write_source($source, $source_filename);
|
||||||
}
|
|
||||||
elsif ($show_diff)
|
|
||||||
{
|
|
||||||
print show_diff($source, $source_filename);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
write_source($source, $source_filename);
|
if ($diff)
|
||||||
|
{
|
||||||
|
print diff($source, $source_filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($check)
|
||||||
|
{
|
||||||
|
$status = 2;
|
||||||
|
last unless $diff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit 0;
|
exit $status;
|
||||||
|
@ -31,13 +31,13 @@ find the file src/tools/pgindent/exclude_file_patterns. The --excludes option
|
|||||||
can be used more than once to specify multiple files containing exclusion
|
can be used more than once to specify multiple files containing exclusion
|
||||||
patterns.
|
patterns.
|
||||||
|
|
||||||
There are also two non-destructive modes of pgindent. If given the --show-diff
|
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
|
option pgindent will show the changes it would make, but doesn't actually make
|
||||||
them. If given instead the --silent-diff option, pgindent will exit with a
|
them. If given instead the --check option, pgindent will exit with a status of
|
||||||
status of 2 if it finds any indent changes are required, but will not
|
2 if it finds any indent changes are required, but will not make the changes.
|
||||||
make the changes or give any other information. This mode is intended for
|
This mode is intended for possible use in a git pre-commit hook. The --check
|
||||||
possible use in a git pre-commit hook. An example of its use in a git hook
|
and --diff options can be combined. An example of its use in a git hook can be
|
||||||
can be seen at https://wiki.postgresql.org/wiki/Working_with_Git#Using_git_hooks
|
seen at https://wiki.postgresql.org/wiki/Working_with_Git#Using_git_hooks
|
||||||
|
|
||||||
Any non-option arguments are taken as the names of files to be indented. In this
|
Any non-option arguments are taken as the names of files to be indented. In this
|
||||||
case only these files will be changed, and nothing else will be touched.
|
case only these files will be changed, and nothing else will be touched.
|
||||||
|
Reference in New Issue
Block a user