Skip to content

Commit 387aecc

Browse files
committed
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
1 parent e6c56f2 commit 387aecc

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

src/tools/pgindent/pgindent

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ my $indent_opts =
2222
my $devnull = File::Spec->devnull;
2323

2424
my ($typedefs_file, $typedef_str, @excludes,
25-
$indent, $build, $show_diff,
26-
$silent_diff, $help, @commits,);
25+
$indent, $build, $diff,
26+
$check, $help, @commits,);
2727

2828
$help = 0;
2929

@@ -34,15 +34,12 @@ my %options = (
3434
"list-of-typedefs=s" => \$typedef_str,
3535
"excludes=s" => \@excludes,
3636
"indent=s" => \$indent,
37-
"show-diff" => \$show_diff,
38-
"silent-diff" => \$silent_diff,);
37+
"diff" => \$diff,
38+
"check" => \$check,);
3939
GetOptions(%options) || usage("bad command line argument");
4040

4141
usage() if $help;
4242

43-
usage("Cannot have both --silent-diff and --show-diff")
44-
if $silent_diff && $show_diff;
45-
4643
usage("Cannot use --commit with command line file list")
4744
if (@commits && @ARGV);
4845

@@ -294,7 +291,7 @@ sub run_indent
294291
return $source;
295292
}
296293

297-
sub show_diff
294+
sub diff
298295
{
299296
my $indented = shift;
300297
my $source_filename = shift;
@@ -323,8 +320,8 @@ Options:
323320
--list-of-typedefs=STR string containing typedefs, space separated
324321
--excludes=PATH file containing list of filename patterns to ignore
325322
--indent=PATH path to pg_bsd_indent program
326-
--show-diff show the changes that would be made
327-
--silent-diff exit with status 2 if any changes would be made
323+
--diff show the changes that would be made
324+
--check exit with status 2 if any changes would be made
328325
The --excludes and --commit options can be given more than once.
329326
EOF
330327
if ($help)
@@ -375,6 +372,7 @@ warn "No files to process" unless @files;
375372
process_exclude();
376373

377374
my %processed;
375+
my $status = 0;
378376

379377
foreach my $source_filename (@files)
380378
{
@@ -417,19 +415,24 @@ foreach my $source_filename (@files)
417415

418416
if ($source ne $orig_source)
419417
{
420-
if ($silent_diff)
421-
{
422-
exit 2;
423-
}
424-
elsif ($show_diff)
418+
if (!$diff && !$check)
425419
{
426-
print show_diff($source, $source_filename);
420+
write_source($source, $source_filename);
427421
}
428422
else
429423
{
430-
write_source($source, $source_filename);
424+
if ($diff)
425+
{
426+
print diff($source, $source_filename);
427+
}
428+
429+
if ($check)
430+
{
431+
$status = 2;
432+
last unless $diff;
433+
}
431434
}
432435
}
433436
}
434437

435-
exit 0;
438+
exit $status;

src/tools/pgindent/pgindent.man

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ find the file src/tools/pgindent/exclude_file_patterns. The --excludes option
3131
can be used more than once to specify multiple files containing exclusion
3232
patterns.
3333

34-
There are also two non-destructive modes of pgindent. If given the --show-diff
34+
There are also two non-destructive modes of pgindent. If given the --diff
3535
option pgindent will show the changes it would make, but doesn't actually make
36-
them. If given instead the --silent-diff option, pgindent will exit with a
37-
status of 2 if it finds any indent changes are required, but will not
38-
make the changes or give any other information. This mode is intended for
39-
possible use in a git pre-commit hook. An example of its use in a git hook
40-
can be seen at https://wiki.postgresql.org/wiki/Working_with_Git#Using_git_hooks
36+
them. If given instead the --check option, pgindent will exit with a status of
37+
2 if it finds any indent changes are required, but will not make the changes.
38+
This mode is intended for possible use in a git pre-commit hook. The --check
39+
and --diff options can be combined. An example of its use in a git hook can be
40+
seen at https://wiki.postgresql.org/wiki/Working_with_Git#Using_git_hooks
4141

4242
Any non-option arguments are taken as the names of files to be indented. In this
4343
case only these files will be changed, and nothing else will be touched.

0 commit comments

Comments
 (0)