pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedAdd --check option to pgindent
31+ messages / 9 participants
[nested] [flat]
Commits from this thread:
2023-12-20 387aecc948 Rename pgindent options
* Add --check option to pgindent
@ 2023-12-12 00:09 Tristan Partin <tristan@neon.tech>
0 siblings, 2 replies; 31+ messages in thread
From: Tristan Partin @ 2023-12-12 00:09 UTC (permalink / raw)
To: pgsql-hackers
Not sold on the name, but --check is a combination of --silent-diff and
--show-diff. I envision --check mostly being used in CI environments.
I recently came across a situation where this behavior would have been
useful. Without --check, you're left to capture the output of
--show-diff and exit 2 if the output isn't empty by yourself.
--
Tristan Partin
Neon (https://neon.tech)
Attachments:
v1-0001-Add-check-option-to-pgindent.patch (text/x-patch, 2.3K) download
From 1001252d49a47e660045cee3d2ba5abd87e925d9 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Mon, 11 Dec 2023 17:34:17 -0600
Subject: [PATCH v1] Add --check option to pgindent
The option is a combination of --show-diff and --silent-diff. It is
useful for situations such as CI checks where the diff can be logged,
but will also cause the build to fail. Without such an option, people
are left to re-implement the same logic over and over again.
---
src/tools/pgindent/pgindent | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index bce63d95da..a285015c76 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -23,7 +23,8 @@ my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
$indent, $build, $show_diff,
- $silent_diff, $help, @commits,);
+ $silent_diff, $help, @commits,
+ $check,);
$help = 0;
@@ -35,7 +36,8 @@ my %options = (
"excludes=s" => \@excludes,
"indent=s" => \$indent,
"show-diff" => \$show_diff,
- "silent-diff" => \$silent_diff,);
+ "silent-diff" => \$silent_diff,
+ "check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
usage() if $help;
@@ -43,6 +45,12 @@ usage() if $help;
usage("Cannot have both --silent-diff and --show-diff")
if $silent_diff && $show_diff;
+usage("Cannot have both --check and --show-diff")
+ if $check && $show_diff;
+
+usage("Cannot have both --check and --silent-diff")
+ if $check && $silent_diff;
+
usage("Cannot use --commit with command line file list")
if (@commits && @ARGV);
@@ -325,6 +333,7 @@ Options:
--indent=PATH path to 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
+ --check combination of --show-diff and --silent-diff
The --excludes and --commit options can be given more than once.
EOF
if ($help)
@@ -417,7 +426,12 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if ($silent_diff)
+ if ($check)
+ {
+ print show_diff($source, $source_filename);
+ exit 2;
+ }
+ elsif ($silent_diff)
{
exit 2;
}
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-12 00:21 Daniel Gustafsson <daniel@yesql.se>
parent: Tristan Partin <tristan@neon.tech>
1 sibling, 0 replies; 31+ messages in thread
From: Daniel Gustafsson @ 2023-12-12 00:21 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; +Cc: pgsql-hackers
> On 12 Dec 2023, at 01:09, Tristan Partin <tristan@neon.tech> wrote:
>
> Not sold on the name, but --check is a combination of --silent-diff and --show-diff. I envision --check mostly being used in CI environments. I recently came across a situation where this behavior would have been useful. Without --check, you're left to capture the output of --show-diff and exit 2 if the output isn't empty by yourself.
I haven’t studied the patch but I can see that being useful.
./daniel
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-12 10:18 Daniel Gustafsson <daniel@yesql.se>
parent: Tristan Partin <tristan@neon.tech>
1 sibling, 1 reply; 31+ messages in thread
From: Daniel Gustafsson @ 2023-12-12 10:18 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; +Cc: pgsql-hackers
> On 12 Dec 2023, at 01:09, Tristan Partin <tristan@neon.tech> wrote:
>
> Not sold on the name, but --check is a combination of --silent-diff and --show-diff. I envision --check mostly being used in CI environments. I recently came across a situation where this behavior would have been useful. Without --check, you're left to capture the output of --show-diff and exit 2 if the output isn't empty by yourself.
I wonder if we should model this around the semantics of git diff to keep it
similar to other CI jobs which often use git diff? git diff --check means "are
there conflicts or issues" which isn't really comparable to here, git diff
--exit-code however is pretty much exactly what this is trying to accomplish.
That would make pgindent --show-diff --exit-code exit with 1 if there were
diffs and 0 if there are no diffs.
--
Daniel Gustafsson
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-12 10:28 Michael Banck <mbanck@gmx.net>
parent: Daniel Gustafsson <daniel@yesql.se>
0 siblings, 1 reply; 31+ messages in thread
From: Michael Banck @ 2023-12-12 10:28 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Tristan Partin <tristan@neon.tech>; pgsql-hackers
Hi,
On Tue, Dec 12, 2023 at 11:18:59AM +0100, Daniel Gustafsson wrote:
> > On 12 Dec 2023, at 01:09, Tristan Partin <tristan@neon.tech> wrote:
> >
> > Not sold on the name, but --check is a combination of --silent-diff
> > and --show-diff. I envision --check mostly being used in CI
> > environments. I recently came across a situation where this behavior
> > would have been useful. Without --check, you're left to capture the
> > output of --show-diff and exit 2 if the output isn't empty by
> > yourself.
>
> I wonder if we should model this around the semantics of git diff to
> keep it similar to other CI jobs which often use git diff? git diff
> --check means "are there conflicts or issues" which isn't really
> comparable to here, git diff --exit-code however is pretty much
> exactly what this is trying to accomplish.
>
> That would make pgindent --show-diff --exit-code exit with 1 if there
> were diffs and 0 if there are no diffs.
To be honest, I find that rather convoluted; contrary to "git diff", I
believe the primary action of pgident is not to show diffs, so I find
the proposed --check option to be entirely reasonable from a UX
perspective.
On the other hand, tying a "does this need re-indenting?" question to a
"--show-diff --exit-code" option combination is not very obvious (to me,
at least).
Cheers,
Michael
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-12 11:47 Euler Taveira <euler@eulerto.com>
parent: Michael Banck <mbanck@gmx.net>
0 siblings, 2 replies; 31+ messages in thread
From: Euler Taveira @ 2023-12-12 11:47 UTC (permalink / raw)
To: Michael Banck <mbanck@gmx.net>; Daniel Gustafsson <daniel@yesql.se>; +Cc: Tristan Partin <tristan@neon.tech>; pgsql-hackers
On Tue, Dec 12, 2023, at 7:28 AM, Michael Banck wrote:
> On Tue, Dec 12, 2023 at 11:18:59AM +0100, Daniel Gustafsson wrote:
> > > On 12 Dec 2023, at 01:09, Tristan Partin <tristan@neon.tech> wrote:
> > >
> > > Not sold on the name, but --check is a combination of --silent-diff
> > > and --show-diff. I envision --check mostly being used in CI
> > > environments. I recently came across a situation where this behavior
> > > would have been useful. Without --check, you're left to capture the
> > > output of --show-diff and exit 2 if the output isn't empty by
> > > yourself.
> >
> > I wonder if we should model this around the semantics of git diff to
> > keep it similar to other CI jobs which often use git diff? git diff
> > --check means "are there conflicts or issues" which isn't really
> > comparable to here, git diff --exit-code however is pretty much
> > exactly what this is trying to accomplish.
> >
> > That would make pgindent --show-diff --exit-code exit with 1 if there
> > were diffs and 0 if there are no diffs.
>
> To be honest, I find that rather convoluted; contrary to "git diff", I
> believe the primary action of pgident is not to show diffs, so I find
> the proposed --check option to be entirely reasonable from a UX
> perspective.
>
> On the other hand, tying a "does this need re-indenting?" question to a
> "--show-diff --exit-code" option combination is not very obvious (to me,
> at least).
Multiple options to accomplish a use case might not be obvious. I'm wondering
if we can combine it into a unique option.
--show-diff show the changes that would be made
--silent-diff exit with status 2 if any changes would be made
+ --check combination of --show-diff and --silent-diff
I mean
--diff=show,silent,check
When you add exceptions, it starts to complicate the UI.
usage("Cannot have both --silent-diff and --show-diff")
if $silent_diff && $show_diff;
+usage("Cannot have both --check and --show-diff")
+ if $check && $show_diff;
+
+usage("Cannot have both --check and --silent-diff")
+ if $check && $silent_diff;
+
--
Euler Taveira
EDB https://www.enterprisedb.com/
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-12 15:18 Tom Lane <tgl@sss.pgh.pa.us>
parent: Euler Taveira <euler@eulerto.com>
1 sibling, 1 reply; 31+ messages in thread
From: Tom Lane @ 2023-12-12 15:18 UTC (permalink / raw)
To: Euler Taveira <euler@eulerto.com>; +Cc: Michael Banck <mbanck@gmx.net>; Daniel Gustafsson <daniel@yesql.se>; Tristan Partin <tristan@neon.tech>; pgsql-hackers
"Euler Taveira" <euler@eulerto.com> writes:
> When you add exceptions, it starts to complicate the UI.
Indeed. It seems like --silent-diff was poorly defined and poorly
named, and we need to rethink that option along the way to adding
this behavior. The idea that --show-diff and --silent-diff can
be used together is just inherently confusing, because they sound
like opposites.
regards, tom lane
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-12 15:26 Tristan Partin <tristan@neon.tech>
parent: Euler Taveira <euler@eulerto.com>
1 sibling, 0 replies; 31+ messages in thread
From: Tristan Partin @ 2023-12-12 15:26 UTC (permalink / raw)
To: Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; Daniel Gustafsson <daniel@yesql.se>; +Cc: pgsql-hackers
On Tue Dec 12, 2023 at 5:47 AM CST, Euler Taveira wrote:
> On Tue, Dec 12, 2023, at 7:28 AM, Michael Banck wrote:
> > On Tue, Dec 12, 2023 at 11:18:59AM +0100, Daniel Gustafsson wrote:
> > > > On 12 Dec 2023, at 01:09, Tristan Partin <tristan@neon.tech> wrote:
> > > >
> > > > Not sold on the name, but --check is a combination of --silent-diff
> > > > and --show-diff. I envision --check mostly being used in CI
> > > > environments. I recently came across a situation where this behavior
> > > > would have been useful. Without --check, you're left to capture the
> > > > output of --show-diff and exit 2 if the output isn't empty by
> > > > yourself.
> > >
> > > I wonder if we should model this around the semantics of git diff to
> > > keep it similar to other CI jobs which often use git diff? git diff
> > > --check means "are there conflicts or issues" which isn't really
> > > comparable to here, git diff --exit-code however is pretty much
> > > exactly what this is trying to accomplish.
> > >
> > > That would make pgindent --show-diff --exit-code exit with 1 if there
> > > were diffs and 0 if there are no diffs.
> >
> > To be honest, I find that rather convoluted; contrary to "git diff", I
> > believe the primary action of pgident is not to show diffs, so I find
> > the proposed --check option to be entirely reasonable from a UX
> > perspective.
> >
> > On the other hand, tying a "does this need re-indenting?" question to a
> > "--show-diff --exit-code" option combination is not very obvious (to me,
> > at least).
>
> Multiple options to accomplish a use case might not be obvious. I'm wondering
> if we can combine it into a unique option.
>
> --show-diff show the changes that would be made
> --silent-diff exit with status 2 if any changes would be made
> + --check combination of --show-diff and --silent-diff
>
> I mean
>
> --diff=show,silent,check
>
> When you add exceptions, it starts to complicate the UI.
>
> usage("Cannot have both --silent-diff and --show-diff")
> if $silent_diff && $show_diff;
>
> +usage("Cannot have both --check and --show-diff")
> + if $check && $show_diff;
> +
> +usage("Cannot have both --check and --silent-diff")
> + if $check && $silent_diff;
> +
I definitely agree. I just didn't want to remove options, but if people
are ok with that, I will just change the interface.
I like the git-diff semantics or have --diff and --check, similar to how
Python's black[0] is.
[0]: https://github.com/psf/black
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-12 15:30 Alvaro Herrera <alvherre@alvh.no-ip.org>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 31+ messages in thread
From: Alvaro Herrera @ 2023-12-12 15:30 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; Daniel Gustafsson <daniel@yesql.se>; Tristan Partin <tristan@neon.tech>; pgsql-hackers
On 2023-Dec-12, Tom Lane wrote:
> "Euler Taveira" <euler@eulerto.com> writes:
> > When you add exceptions, it starts to complicate the UI.
>
> Indeed. It seems like --silent-diff was poorly defined and poorly
> named, and we need to rethink that option along the way to adding
> this behavior. The idea that --show-diff and --silent-diff can
> be used together is just inherently confusing, because they sound
> like opposites.
Maybe it's enough to rename --silent-diff to --check. You can do
"--show-diff --check" and get both the error and the diff printed; or
just "--check" and it'll throw an error without further ado; or
"--show-diff" and it will both apply the diff and print it.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"I must say, I am absolutely impressed with what pgsql's implementation of
VALUES allows me to do. It's kind of ridiculous how much "work" goes away in
my code. Too bad I can't do this at work (Oracle 8/9)." (Tom Allison)
http://archives.postgresql.org/pgsql-general/2007-06/msg00016.php
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-13 20:46 Andrew Dunstan <andrew@dunslane.net>
parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 1 reply; 31+ messages in thread
From: Andrew Dunstan @ 2023-12-13 20:46 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; Daniel Gustafsson <daniel@yesql.se>; Tristan Partin <tristan@neon.tech>; pgsql-hackers
On 2023-12-12 Tu 10:30, Alvaro Herrera wrote:
> On 2023-Dec-12, Tom Lane wrote:
>
>> "Euler Taveira" <euler@eulerto.com> writes:
>>> When you add exceptions, it starts to complicate the UI.
>> Indeed. It seems like --silent-diff was poorly defined and poorly
>> named, and we need to rethink that option along the way to adding
>> this behavior. The idea that --show-diff and --silent-diff can
>> be used together is just inherently confusing, because they sound
>> like opposites
> Maybe it's enough to rename --silent-diff to --check. You can do
> "--show-diff --check" and get both the error and the diff printed; or
> just "--check" and it'll throw an error without further ado; or
> "--show-diff" and it will both apply the diff and print it.
>
That seems reasonable. These features were fairly substantially debated
when we put them in, but I'm fine with some tweaking. But note:
--show-diff doesn't apply the diff, it's intentionally non-destructive.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-14 16:53 Tristan Partin <tristan@neon.tech>
parent: Andrew Dunstan <andrew@dunslane.net>
0 siblings, 1 reply; 31+ messages in thread
From: Tristan Partin @ 2023-12-14 16:53 UTC (permalink / raw)
To: Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; Daniel Gustafsson <daniel@yesql.se>; pgsql-hackers
On Wed Dec 13, 2023 at 2:46 PM CST, Andrew Dunstan wrote:
>
> On 2023-12-12 Tu 10:30, Alvaro Herrera wrote:
> > On 2023-Dec-12, Tom Lane wrote:
> >
> >> "Euler Taveira" <euler@eulerto.com> writes:
> >>> When you add exceptions, it starts to complicate the UI.
> >> Indeed. It seems like --silent-diff was poorly defined and poorly
> >> named, and we need to rethink that option along the way to adding
> >> this behavior. The idea that --show-diff and --silent-diff can
> >> be used together is just inherently confusing, because they sound
> >> like opposites
> > Maybe it's enough to rename --silent-diff to --check. You can do
> > "--show-diff --check" and get both the error and the diff printed; or
> > just "--check" and it'll throw an error without further ado; or
> > "--show-diff" and it will both apply the diff and print it.
> >
>
> That seems reasonable. These features were fairly substantially debated
> when we put them in, but I'm fine with some tweaking. But note:
> --show-diff doesn't apply the diff, it's intentionally non-destructive.
Here is a new patch:
- Renames --silent-diff to --check
- Renames --show-diff to --diff
- Allows one to use --check and --diff in the same command
I am not tied to the second patch if people like --show-diff better than
--diff.
Weirdly enough, my email client doesn't show this as part of the
original thread, but I will respond here anyway.
--
Tristan Partin
Neon (https://neon.tech)
Attachments: download all (3 files, .tar.gz)
v2-0001-Rename-silent-diff-to-check-in-pgindent.patch (text/x-patch, 2.0K) download
From f0963daa95b222b00a7ae15d6702141352d3a81d Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Mon, 11 Dec 2023 17:34:17 -0600
Subject: [PATCH v2 1/3] Rename --silent-diff to --check in pgindent
--check should be a little bit more self-explanatory for people coming
from other similar formatter/linting tooling.
---
src/tools/pgindent/pgindent | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index bce63d95da..fe0bd21f4a 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -23,7 +23,7 @@ my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
$indent, $build, $show_diff,
- $silent_diff, $help, @commits,);
+ $check, $help, @commits,);
$help = 0;
@@ -35,13 +35,13 @@ my %options = (
"excludes=s" => \@excludes,
"indent=s" => \$indent,
"show-diff" => \$show_diff,
- "silent-diff" => \$silent_diff,);
+ "check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
usage() if $help;
-usage("Cannot have both --silent-diff and --show-diff")
- if $silent_diff && $show_diff;
+usage("Cannot have both --check and --show-diff")
+ if $check && $show_diff;
usage("Cannot use --commit with command line file list")
if (@commits && @ARGV);
@@ -324,7 +324,7 @@ Options:
--excludes=PATH file containing list of filename patterns to ignore
--indent=PATH path to 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
+ --check exit with status 2 if any changes would be made
The --excludes and --commit options can be given more than once.
EOF
if ($help)
@@ -417,7 +417,12 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if ($silent_diff)
+ if ($check)
+ {
+ print show_diff($source, $source_filename);
+ exit 2;
+ }
+ elsif ($check)
{
exit 2;
}
--
Tristan Partin
Neon (https://neon.tech)
v2-0002-Rename-show-diff-to-diff-in-pgindent.patch (text/x-patch, 2.4K) download
From ddd5cdaf8e967ddf84beb49ca64b5bed039b71ac Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Thu, 14 Dec 2023 10:36:05 -0600
Subject: [PATCH v2 2/3] Rename --show-diff to --diff in pgindent
--diff should be a little bit more self-explanatory for people coming
from other similar formatter/linting tooling.
---
src/tools/pgindent/pgindent | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index fe0bd21f4a..067b77be54 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -22,7 +22,7 @@ my $indent_opts =
my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
- $indent, $build, $show_diff,
+ $indent, $build, $diff,
$check, $help, @commits,);
$help = 0;
@@ -34,14 +34,14 @@ my %options = (
"list-of-typedefs=s" => \$typedef_str,
"excludes=s" => \@excludes,
"indent=s" => \$indent,
- "show-diff" => \$show_diff,
+ "diff" => \$diff,
"check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
usage() if $help;
-usage("Cannot have both --check and --show-diff")
- if $check && $show_diff;
+usage("Cannot have both --check and --diff")
+ if $check && $diff;
usage("Cannot use --commit with command line file list")
if (@commits && @ARGV);
@@ -294,7 +294,7 @@ sub run_indent
return $source;
}
-sub show_diff
+sub diff
{
my $indented = shift;
my $source_filename = shift;
@@ -323,7 +323,7 @@ Options:
--list-of-typedefs=STR string containing typedefs, space separated
--excludes=PATH file containing list of filename patterns to ignore
--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
--check exit with status 2 if any changes would be made
The --excludes and --commit options can be given more than once.
EOF
@@ -419,16 +419,16 @@ foreach my $source_filename (@files)
{
if ($check)
{
- print show_diff($source, $source_filename);
+ print diff($source, $source_filename);
exit 2;
}
elsif ($check)
{
exit 2;
}
- elsif ($show_diff)
+ elsif ($diff)
{
- print show_diff($source, $source_filename);
+ print diff($source, $source_filename);
}
else
{
--
Tristan Partin
Neon (https://neon.tech)
v2-0003-Allow-check-and-diff-to-passed-in-the-same-pginde.patch (text/x-patch, 1.4K) download
From 936fb5af395dbbc5fca56ac3a2eaae8216992159 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Thu, 14 Dec 2023 10:39:32 -0600
Subject: [PATCH v2 3/3] Allow --check and --diff to passed in the same
pgindent command
This means to print the diff and exit if a diff exists.
---
src/tools/pgindent/pgindent | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 067b77be54..f69923fb00 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -40,9 +40,6 @@ GetOptions(%options) || usage("bad command line argument");
usage() if $help;
-usage("Cannot have both --check and --diff")
- if $check && $diff;
-
usage("Cannot use --commit with command line file list")
if (@commits && @ARGV);
@@ -417,22 +414,21 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if ($check)
- {
- print diff($source, $source_filename);
- exit 2;
- }
- elsif ($check)
+ if (!$show_diff && !$check)
{
- exit 2;
- }
- elsif ($diff)
- {
- print diff($source, $source_filename);
+ write_source($source, $source_filename);
}
else
{
- write_source($source, $source_filename);
+ if ($show_diff)
+ {
+ print diff($source, $source_filename);
+ }
+
+ if ($check)
+ {
+ exit 2;
+ }
}
}
}
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-15 14:18 Jelte Fennema-Nio <postgres@jeltef.nl>
parent: Tristan Partin <tristan@neon.tech>
0 siblings, 1 reply; 31+ messages in thread
From: Jelte Fennema-Nio @ 2023-12-15 14:18 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; +Cc: Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; Daniel Gustafsson <daniel@yesql.se>; pgsql-hackers
This part of the first patch seems incorrect, i.e. same condition in
the if as elsif
- if ($silent_diff)
+ if ($check)
+ {
+ print show_diff($source, $source_filename);
+ exit 2;
+ }
+ elsif ($check)
{
exit 2;
}
On Thu, 14 Dec 2023 at 17:54, Tristan Partin <tristan@neon.tech> wrote:
>
> On Wed Dec 13, 2023 at 2:46 PM CST, Andrew Dunstan wrote:
> >
> > On 2023-12-12 Tu 10:30, Alvaro Herrera wrote:
> > > On 2023-Dec-12, Tom Lane wrote:
> > >
> > >> "Euler Taveira" <euler@eulerto.com> writes:
> > >>> When you add exceptions, it starts to complicate the UI.
> > >> Indeed. It seems like --silent-diff was poorly defined and poorly
> > >> named, and we need to rethink that option along the way to adding
> > >> this behavior. The idea that --show-diff and --silent-diff can
> > >> be used together is just inherently confusing, because they sound
> > >> like opposites
> > > Maybe it's enough to rename --silent-diff to --check. You can do
> > > "--show-diff --check" and get both the error and the diff printed; or
> > > just "--check" and it'll throw an error without further ado; or
> > > "--show-diff" and it will both apply the diff and print it.
> > >
> >
> > That seems reasonable. These features were fairly substantially debated
> > when we put them in, but I'm fine with some tweaking. But note:
> > --show-diff doesn't apply the diff, it's intentionally non-destructive.
>
> Here is a new patch:
>
> - Renames --silent-diff to --check
> - Renames --show-diff to --diff
> - Allows one to use --check and --diff in the same command
>
> I am not tied to the second patch if people like --show-diff better than
> --diff.
>
> Weirdly enough, my email client doesn't show this as part of the
> original thread, but I will respond here anyway.
>
> --
> Tristan Partin
> Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-15 15:43 Tristan Partin <tristan@neon.tech>
parent: Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 1 reply; 31+ messages in thread
From: Tristan Partin @ 2023-12-15 15:43 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; Daniel Gustafsson <daniel@yesql.se>; pgsql-hackers
On Fri Dec 15, 2023 at 8:18 AM CST, Jelte Fennema-Nio wrote:
> This part of the first patch seems incorrect, i.e. same condition in
> the if as elsif
>
> - if ($silent_diff)
> + if ($check)
> + {
> + print show_diff($source, $source_filename);
> + exit 2;
> + }
> + elsif ($check)
> {
> exit 2;
> }
Weird how I was able to screw that up so bad :). Thanks! Here is a v3.
--
Tristan Partin
Neon (https://neon.tech)
Attachments: download all (3 files, .tar.gz)
v3-0001-Rename-silent-diff-to-check-in-pgindent.patch (text/x-patch, 2.0K) download
From ed5a44a1552c407719ac8c94603b51a7e72084f0 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Mon, 11 Dec 2023 17:34:17 -0600
Subject: [PATCH v3 1/3] Rename --silent-diff to --check in pgindent
--check should be a little bit more self-explanatory for people coming
from other similar formatter/linting tooling.
---
src/tools/pgindent/pgindent | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index bce63d95da..ca5f8543a6 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -23,7 +23,7 @@ my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
$indent, $build, $show_diff,
- $silent_diff, $help, @commits,);
+ $check, $help, @commits,);
$help = 0;
@@ -35,13 +35,13 @@ my %options = (
"excludes=s" => \@excludes,
"indent=s" => \$indent,
"show-diff" => \$show_diff,
- "silent-diff" => \$silent_diff,);
+ "check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
usage() if $help;
-usage("Cannot have both --silent-diff and --show-diff")
- if $silent_diff && $show_diff;
+usage("Cannot have both --check and --show-diff")
+ if $check && $show_diff;
usage("Cannot use --commit with command line file list")
if (@commits && @ARGV);
@@ -324,7 +324,7 @@ Options:
--excludes=PATH file containing list of filename patterns to ignore
--indent=PATH path to 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
+ --check exit with status 2 if any changes would be made
The --excludes and --commit options can be given more than once.
EOF
if ($help)
@@ -417,7 +417,7 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if ($silent_diff)
+ if ($check)
{
exit 2;
}
--
Tristan Partin
Neon (https://neon.tech)
v3-0002-Rename-show-diff-to-diff-in-pgindent.patch (text/x-patch, 2.2K) download
From 370539a8a86fea310a8e33c7298786923039dd13 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Thu, 14 Dec 2023 10:36:05 -0600
Subject: [PATCH v3 2/3] Rename --show-diff to --diff in pgindent
--diff should be a little bit more self-explanatory for people coming
from other similar formatter/linting tooling.
---
src/tools/pgindent/pgindent | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index ca5f8543a6..38a0222573 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -22,7 +22,7 @@ my $indent_opts =
my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
- $indent, $build, $show_diff,
+ $indent, $build, $diff,
$check, $help, @commits,);
$help = 0;
@@ -34,14 +34,14 @@ my %options = (
"list-of-typedefs=s" => \$typedef_str,
"excludes=s" => \@excludes,
"indent=s" => \$indent,
- "show-diff" => \$show_diff,
+ "diff" => \$diff,
"check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
usage() if $help;
-usage("Cannot have both --check and --show-diff")
- if $check && $show_diff;
+usage("Cannot have both --check and --diff")
+ if $check && $diff;
usage("Cannot use --commit with command line file list")
if (@commits && @ARGV);
@@ -294,7 +294,7 @@ sub run_indent
return $source;
}
-sub show_diff
+sub diff
{
my $indented = shift;
my $source_filename = shift;
@@ -323,7 +323,7 @@ Options:
--list-of-typedefs=STR string containing typedefs, space separated
--excludes=PATH file containing list of filename patterns to ignore
--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
--check exit with status 2 if any changes would be made
The --excludes and --commit options can be given more than once.
EOF
@@ -421,9 +421,9 @@ foreach my $source_filename (@files)
{
exit 2;
}
- elsif ($show_diff)
+ elsif ($diff)
{
- print show_diff($source, $source_filename);
+ print diff($source, $source_filename);
}
else
{
--
Tristan Partin
Neon (https://neon.tech)
v3-0003-Allow-check-and-diff-to-passed-in-the-same-pginde.patch (text/x-patch, 1.3K) download
From 57ceebbc81f97da2e6ca28d8c145918732be5382 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Thu, 14 Dec 2023 10:39:32 -0600
Subject: [PATCH v3 3/3] Allow --check and --diff to passed in the same
pgindent command
This means to print the diff and exit if a diff exists.
---
src/tools/pgindent/pgindent | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 38a0222573..eb2f52f4b9 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -40,9 +40,6 @@ GetOptions(%options) || usage("bad command line argument");
usage() if $help;
-usage("Cannot have both --check and --diff")
- if $check && $diff;
-
usage("Cannot use --commit with command line file list")
if (@commits && @ARGV);
@@ -417,17 +414,21 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if ($check)
- {
- exit 2;
- }
- elsif ($diff)
+ if (!$diff && !$check)
{
- print diff($source, $source_filename);
+ write_source($source, $source_filename);
}
else
{
- write_source($source, $source_filename);
+ if ($diff)
+ {
+ print diff($source, $source_filename);
+ }
+
+ if ($check)
+ {
+ exit 2;
+ }
}
}
}
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 12:41 Daniel Gustafsson <daniel@yesql.se>
parent: Tristan Partin <tristan@neon.tech>
0 siblings, 3 replies; 31+ messages in thread
From: Daniel Gustafsson @ 2023-12-18 12:41 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
> On 15 Dec 2023, at 16:43, Tristan Partin <tristan@neon.tech> wrote:
> Here is a v3.
I think this is pretty much ready to go, the attached v4 squashes the changes
and fixes the man-page which also needed an update. The referenced Wiki page
will need an edit or two after this goes in, but that's easy enough.
--
Daniel Gustafsson
Attachments:
v4-0001-Rename-non-destructive-modes-in-pgindent.patch (application/octet-stream, 4.3K) download
From a7a3ad02f6c61e8705ae89698ff007bc1c640ecf Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Mon, 18 Dec 2023 13:22:12 +0100
Subject: [PATCH v4] Rename non-destructive modes in pgindent
This renames --silent-diff to --check and --show-diff to --diff,
in order to make the options a little bit more self-explanatory
for developers used to similar formatters/linters. --check and
--diff are also allowed to be combined.
Author: Tristan Partin <tristan@neon.tech>
Discussion: https://postgr.es/m/CXLX2XYTH9S6.140SC6Y61VD88@neon.tech
---
src/tools/pgindent/pgindent | 35 +++++++++++++++++----------------
src/tools/pgindent/pgindent.man | 12 +++++------
2 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index bce63d95da..eb2f52f4b9 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -22,8 +22,8 @@ my $indent_opts =
my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
- $indent, $build, $show_diff,
- $silent_diff, $help, @commits,);
+ $indent, $build, $diff,
+ $check, $help, @commits,);
$help = 0;
@@ -34,15 +34,12 @@ my %options = (
"list-of-typedefs=s" => \$typedef_str,
"excludes=s" => \@excludes,
"indent=s" => \$indent,
- "show-diff" => \$show_diff,
- "silent-diff" => \$silent_diff,);
+ "diff" => \$diff,
+ "check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
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")
if (@commits && @ARGV);
@@ -294,7 +291,7 @@ sub run_indent
return $source;
}
-sub show_diff
+sub diff
{
my $indented = shift;
my $source_filename = shift;
@@ -323,8 +320,8 @@ Options:
--list-of-typedefs=STR string containing typedefs, space separated
--excludes=PATH file containing list of filename patterns to ignore
--indent=PATH path to 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
+ --diff show the changes that 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.
EOF
if ($help)
@@ -417,17 +414,21 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if ($silent_diff)
- {
- exit 2;
- }
- elsif ($show_diff)
+ if (!$diff && !$check)
{
- print show_diff($source, $source_filename);
+ write_source($source, $source_filename);
}
else
{
- write_source($source, $source_filename);
+ if ($diff)
+ {
+ print diff($source, $source_filename);
+ }
+
+ if ($check)
+ {
+ exit 2;
+ }
}
}
}
diff --git a/src/tools/pgindent/pgindent.man b/src/tools/pgindent/pgindent.man
index fe411ee699..caab5cde91 100644
--- a/src/tools/pgindent/pgindent.man
+++ b/src/tools/pgindent/pgindent.man
@@ -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
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
-them. If given instead the --silent-diff option, pgindent will exit with a
-status of 2 if it finds any indent changes are required, but will not
-make the changes or give any other information. This mode is intended for
-possible use in a git pre-commit hook. An example of its use in a git hook
-can be seen at https://wiki.postgresql.org/wiki/Working_with_Git#Using_git_hooks
+them. If given instead the --check option, pgindent will exit with a status of
+2 if it finds any indent changes are required, but will not make the changes.
+This mode is intended for possible use in a git pre-commit hook. The --check
+and --diff options can be combined. An example of its use in a git hook can be
+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
case only these files will be changed, and nothing else will be touched.
--
2.32.1 (Apple Git-133)
=
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 13:56 Euler Taveira <euler@eulerto.com>
parent: Daniel Gustafsson <daniel@yesql.se>
2 siblings, 1 reply; 31+ messages in thread
From: Euler Taveira @ 2023-12-18 13:56 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; Tristan Partin <tristan@neon.tech>; +Cc: Jelte Fennema <postgres@jeltef.nl>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon, Dec 18, 2023, at 9:41 AM, Daniel Gustafsson wrote:
> > On 15 Dec 2023, at 16:43, Tristan Partin <tristan@neon.tech> wrote:
>
> > Here is a v3.
>
> I think this is pretty much ready to go, the attached v4 squashes the changes
> and fixes the man-page which also needed an update. The referenced Wiki page
> will need an edit or two after this goes in, but that's easy enough.
... and pgbuildfarm client [1] needs to be changed too.
[1] https://github.com/PGBuildFarm/client-code/blob/main/PGBuild/Modules/CheckIndent.pm#L55-L90
--
Euler Taveira
EDB https://www.enterprisedb.com/
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 15:45 Tristan Partin <tristan@neon.tech>
parent: Daniel Gustafsson <daniel@yesql.se>
2 siblings, 1 reply; 31+ messages in thread
From: Tristan Partin @ 2023-12-18 15:45 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon Dec 18, 2023 at 6:41 AM CST, Daniel Gustafsson wrote:
> > On 15 Dec 2023, at 16:43, Tristan Partin <tristan@neon.tech> wrote:
>
> > Here is a v3.
>
> I think this is pretty much ready to go, the attached v4 squashes the changes
> and fixes the man-page which also needed an update. The referenced Wiki page
> will need an edit or two after this goes in, but that's easy enough.
I have never edited the Wiki before. How can I do that? More than happy
to do it.
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 15:45 Tristan Partin <tristan@neon.tech>
parent: Euler Taveira <euler@eulerto.com>
0 siblings, 0 replies; 31+ messages in thread
From: Tristan Partin @ 2023-12-18 15:45 UTC (permalink / raw)
To: Euler Taveira <euler@eulerto.com>; Daniel Gustafsson <daniel@yesql.se>; +Cc: Jelte Fennema <postgres@jeltef.nl>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon Dec 18, 2023 at 7:56 AM CST, Euler Taveira wrote:
> On Mon, Dec 18, 2023, at 9:41 AM, Daniel Gustafsson wrote:
> > > On 15 Dec 2023, at 16:43, Tristan Partin <tristan@neon.tech> wrote:
> >
> > > Here is a v3.
> >
> > I think this is pretty much ready to go, the attached v4 squashes the changes
> > and fixes the man-page which also needed an update. The referenced Wiki page
> > will need an edit or two after this goes in, but that's easy enough.
>
> ... and pgbuildfarm client [1] needs to be changed too.
>
>
> [1] https://github.com/PGBuildFarm/client-code/blob/main/PGBuild/Modules/CheckIndent.pm#L55-L90
Thanks Euler. I am on it.
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 15:59 Matthias van de Meent <boekewurm+postgres@gmail.com>
parent: Tristan Partin <tristan@neon.tech>
0 siblings, 0 replies; 31+ messages in thread
From: Matthias van de Meent @ 2023-12-18 15:59 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Jelte Fennema-Nio <postgres@jeltef.nl>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon, 18 Dec 2023 at 16:45, Tristan Partin <tristan@neon.tech> wrote:
>
> On Mon Dec 18, 2023 at 6:41 AM CST, Daniel Gustafsson wrote:
> > > On 15 Dec 2023, at 16:43, Tristan Partin <tristan@neon.tech> wrote:
> >
> > > Here is a v3.
> >
> > I think this is pretty much ready to go, the attached v4 squashes the changes
> > and fixes the man-page which also needed an update. The referenced Wiki page
> > will need an edit or two after this goes in, but that's easy enough.
>
> I have never edited the Wiki before. How can I do that? More than happy
> to do it.
As mentioned at the bottom of the main page of the wiki:
NOTE: due to recent spam activity "editor" privileges are granted
manually for the time being.
If you just created a new community account or if your current
account used to have "editor" privileges ask on either the PostgreSQL
-www Mailinglist or the PostgreSQL IRC Channel (direct your request to
'pginfra', multiple individuals in the channel highlight on that
string) for help. Please include your community account name in those
requests.
After that, it's just a case of loggin in on the wiki (link top right
corner, which uses the community account) and then just go on to your
prefered page, click edit, and do your modifications. Don't forget to
save the modifications - I'm not sure whether the wiki editor's state
is locally persisted.
Kind regards,
Matthias van de Meent
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 16:14 Jelte Fennema-Nio <postgres@jeltef.nl>
parent: Daniel Gustafsson <daniel@yesql.se>
2 siblings, 3 replies; 31+ messages in thread
From: Jelte Fennema-Nio @ 2023-12-18 16:14 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Tristan Partin <tristan@neon.tech>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon, 18 Dec 2023 at 13:42, Daniel Gustafsson <daniel@yesql.se> wrote:
> I think this is pretty much ready to go, the attached v4 squashes the changes
> and fixes the man-page which also needed an update. The referenced Wiki page
> will need an edit or two after this goes in, but that's easy enough.
One thing I'm wondering: When both --check and --diff are passed,
should pgindent still early exit with 2 on the first incorrectly
formatted file? Or should it show diffs for all failing files? I'm
leaning towards the latter making more sense.
Related (but not required for this patch): For my pre-commit hook I
would very much like it if there was an option to have pgindent write
the changes to disk, but still exit non-zero, e.g. a --write flag that
could be combined with --check just like --diff and --check can be
combined with this patch. Currently my pre-commit hook need two
separate calls to pgindent to both abort the commit and write the
required changes to disk.
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 16:15 Jelte Fennema-Nio <postgres@jeltef.nl>
parent: Jelte Fennema-Nio <postgres@jeltef.nl>
2 siblings, 0 replies; 31+ messages in thread
From: Jelte Fennema-Nio @ 2023-12-18 16:15 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Tristan Partin <tristan@neon.tech>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon, 18 Dec 2023 at 17:14, Jelte Fennema-Nio <postgres@jeltef.nl> wrote:
> One thing I'm wondering: When both --check and --diff are passed,
> should pgindent still early exit with 2 on the first incorrectly
> formatted file? Or should it show diffs for all failing files? I'm
> leaning towards the latter making more sense.
To be clear, in the latter case it would still exit with 2 at the end
of the script, but only after showing diffs for all files.
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 16:50 Tristan Partin <tristan@neon.tech>
parent: Jelte Fennema-Nio <postgres@jeltef.nl>
2 siblings, 2 replies; 31+ messages in thread
From: Tristan Partin @ 2023-12-18 16:50 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; Daniel Gustafsson <daniel@yesql.se>; +Cc: Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon Dec 18, 2023 at 10:14 AM CST, Jelte Fennema-Nio wrote:
> On Mon, 18 Dec 2023 at 13:42, Daniel Gustafsson <daniel@yesql.se> wrote:
> > I think this is pretty much ready to go, the attached v4 squashes the changes
> > and fixes the man-page which also needed an update. The referenced Wiki page
> > will need an edit or two after this goes in, but that's easy enough.
>
> One thing I'm wondering: When both --check and --diff are passed,
> should pgindent still early exit with 2 on the first incorrectly
> formatted file? Or should it show diffs for all failing files? I'm
> leaning towards the latter making more sense.
Makes sense. Let me iterate on the squashed version of the patch.
> Related (but not required for this patch): For my pre-commit hook I
> would very much like it if there was an option to have pgindent write
> the changes to disk, but still exit non-zero, e.g. a --write flag that
> could be combined with --check just like --diff and --check can be
> combined with this patch. Currently my pre-commit hook need two
> separate calls to pgindent to both abort the commit and write the
> required changes to disk.
I could propose something. It would help if I had an example of such
a tool that already exists.
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 17:21 Jelte Fennema-Nio <postgres@jeltef.nl>
parent: Tristan Partin <tristan@neon.tech>
1 sibling, 1 reply; 31+ messages in thread
From: Jelte Fennema-Nio @ 2023-12-18 17:21 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon, 18 Dec 2023 at 17:50, Tristan Partin <tristan@neon.tech> wrote:
> I could propose something. It would help if I had an example of such
> a tool that already exists.
Basically the same behaviour as what you're trying to add now for
--check, only instead of printing the diff it would actually change
the files just like running pgindent without a --check flag does. i.e.
allow pgindent --check to not run in "dry-run" mode
My pre-commit hook looks like this currently (removed boring cruft around it):
if ! src/tools/pgindent/pgindent --check $files > /dev/null; then
exit 0
fi
echo "Running pgindent on changed files"
src/tools/pgindent/pgindent $files
echo "Commit abandoned. Rerun git commit to adopt pgindent changes"
exit 1
But I would like it to look like:
if src/tools/pgindent/pgindent --check --write $files > /dev/null; then
exit 0
fi
echo "Commit abandoned. Rerun git commit to adopt pgindent changes"
exit 1
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 21:18 Tristan Partin <tristan@neon.tech>
parent: Tristan Partin <tristan@neon.tech>
1 sibling, 2 replies; 31+ messages in thread
From: Tristan Partin @ 2023-12-18 21:18 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; Jelte Fennema-Nio <postgres@jeltef.nl>; Daniel Gustafsson <daniel@yesql.se>; +Cc: Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon Dec 18, 2023 at 10:50 AM CST, Tristan Partin wrote:
> On Mon Dec 18, 2023 at 10:14 AM CST, Jelte Fennema-Nio wrote:
> > On Mon, 18 Dec 2023 at 13:42, Daniel Gustafsson <daniel@yesql.se> wrote:
> > > I think this is pretty much ready to go, the attached v4 squashes the changes
> > > and fixes the man-page which also needed an update. The referenced Wiki page
> > > will need an edit or two after this goes in, but that's easy enough.
> >
> > One thing I'm wondering: When both --check and --diff are passed,
> > should pgindent still early exit with 2 on the first incorrectly
> > formatted file? Or should it show diffs for all failing files? I'm
> > leaning towards the latter making more sense.
>
> Makes sense. Let me iterate on the squashed version of the patch.
Here is an additional patch which implements the behavior you described.
The first patch is just Daniel's squashed version of my patches.
--
Tristan Partin
Neon (https://neon.tech)
Attachments: download all (2 files, .tar.gz)
v5-0001-Rename-non-destructive-modes-in-pgindent.patch (text/x-patch, 4.4K) download
From 5cd4c5e9af0fc6e2e385b79111a6cca66df6cad9 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Mon, 18 Dec 2023 13:22:12 +0100
Subject: [PATCH v5 1/2] Rename non-destructive modes in pgindent
This renames --silent-diff to --check and --show-diff to --diff,
in order to make the options a little bit more self-explanatory
for developers used to similar formatters/linters. --check and
--diff are also allowed to be combined.
Author: Tristan Partin <tristan@neon.tech>
Discussion: https://postgr.es/m/CXLX2XYTH9S6.140SC6Y61VD88@neon.tech
---
src/tools/pgindent/pgindent | 35 +++++++++++++++++----------------
src/tools/pgindent/pgindent.man | 12 +++++------
2 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index bce63d95da..eb2f52f4b9 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -22,8 +22,8 @@ my $indent_opts =
my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
- $indent, $build, $show_diff,
- $silent_diff, $help, @commits,);
+ $indent, $build, $diff,
+ $check, $help, @commits,);
$help = 0;
@@ -34,15 +34,12 @@ my %options = (
"list-of-typedefs=s" => \$typedef_str,
"excludes=s" => \@excludes,
"indent=s" => \$indent,
- "show-diff" => \$show_diff,
- "silent-diff" => \$silent_diff,);
+ "diff" => \$diff,
+ "check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
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")
if (@commits && @ARGV);
@@ -294,7 +291,7 @@ sub run_indent
return $source;
}
-sub show_diff
+sub diff
{
my $indented = shift;
my $source_filename = shift;
@@ -323,8 +320,8 @@ Options:
--list-of-typedefs=STR string containing typedefs, space separated
--excludes=PATH file containing list of filename patterns to ignore
--indent=PATH path to 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
+ --diff show the changes that 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.
EOF
if ($help)
@@ -417,17 +414,21 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if ($silent_diff)
- {
- exit 2;
- }
- elsif ($show_diff)
+ if (!$diff && !$check)
{
- print show_diff($source, $source_filename);
+ write_source($source, $source_filename);
}
else
{
- write_source($source, $source_filename);
+ if ($diff)
+ {
+ print diff($source, $source_filename);
+ }
+
+ if ($check)
+ {
+ exit 2;
+ }
}
}
}
diff --git a/src/tools/pgindent/pgindent.man b/src/tools/pgindent/pgindent.man
index fe411ee699..caab5cde91 100644
--- a/src/tools/pgindent/pgindent.man
+++ b/src/tools/pgindent/pgindent.man
@@ -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
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
-them. If given instead the --silent-diff option, pgindent will exit with a
-status of 2 if it finds any indent changes are required, but will not
-make the changes or give any other information. This mode is intended for
-possible use in a git pre-commit hook. An example of its use in a git hook
-can be seen at https://wiki.postgresql.org/wiki/Working_with_Git#Using_git_hooks
+them. If given instead the --check option, pgindent will exit with a status of
+2 if it finds any indent changes are required, but will not make the changes.
+This mode is intended for possible use in a git pre-commit hook. The --check
+and --diff options can be combined. An example of its use in a git hook can be
+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
case only these files will be changed, and nothing else will be touched.
--
Tristan Partin
Neon (https://neon.tech)
v5-0002-Print-all-diffs-with-pgindent-check.patch (text/x-patch, 924B) download
From 131c44536c83c01097de9253f7b09bdd7f2c2b4c Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Mon, 18 Dec 2023 15:14:56 -0600
Subject: [PATCH v5 2/2] Print all diffs with pgindent --check
Previously, only one diff was printed if multiple files were out of
compliance.
---
src/tools/pgindent/pgindent | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index eb2f52f4b9..0ae4dcddb1 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -372,6 +372,7 @@ warn "No files to process" unless @files;
process_exclude();
my %processed;
+my $status = 0;
foreach my $source_filename (@files)
{
@@ -427,10 +428,10 @@ foreach my $source_filename (@files)
if ($check)
{
- exit 2;
+ $status = 2;
}
}
}
}
-exit 0;
+exit $status;
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-18 21:34 Tristan Partin <tristan@neon.tech>
parent: Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 0 replies; 31+ messages in thread
From: Tristan Partin @ 2023-12-18 21:34 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon Dec 18, 2023 at 11:21 AM CST, Jelte Fennema-Nio wrote:
> On Mon, 18 Dec 2023 at 17:50, Tristan Partin <tristan@neon.tech> wrote:
> > I could propose something. It would help if I had an example of such
> > a tool that already exists.
>
> Basically the same behaviour as what you're trying to add now for
> --check, only instead of printing the diff it would actually change
> the files just like running pgindent without a --check flag does. i.e.
> allow pgindent --check to not run in "dry-run" mode
> My pre-commit hook looks like this currently (removed boring cruft around it):
>
> if ! src/tools/pgindent/pgindent --check $files > /dev/null; then
> exit 0
> fi
> echo "Running pgindent on changed files"
> src/tools/pgindent/pgindent $files
> echo "Commit abandoned. Rerun git commit to adopt pgindent changes"
> exit 1
>
> But I would like it to look like:
>
> if src/tools/pgindent/pgindent --check --write $files > /dev/null; then
> exit 0
> fi
> echo "Commit abandoned. Rerun git commit to adopt pgindent changes"
> exit 1
To me, the two options seem at odds, like you either check or write. How
would you feel about just capturing the diffs that are printed and
patch(1)-ing them?
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-19 13:51 Andrew Dunstan <andrew@dunslane.net>
parent: Jelte Fennema-Nio <postgres@jeltef.nl>
2 siblings, 1 reply; 31+ messages in thread
From: Andrew Dunstan @ 2023-12-19 13:51 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; Daniel Gustafsson <daniel@yesql.se>; +Cc: Tristan Partin <tristan@neon.tech>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On 2023-12-18 Mo 11:14, Jelte Fennema-Nio wrote:
> On Mon, 18 Dec 2023 at 13:42, Daniel Gustafsson <daniel@yesql.se> wrote:
>> I think this is pretty much ready to go, the attached v4 squashes the changes
>> and fixes the man-page which also needed an update. The referenced Wiki page
>> will need an edit or two after this goes in, but that's easy enough.
> One thing I'm wondering: When both --check and --diff are passed,
> should pgindent still early exit with 2 on the first incorrectly
> formatted file? Or should it show diffs for all failing files? I'm
> leaning towards the latter making more sense.
It should show them all.
>
> Related (but not required for this patch): For my pre-commit hook I
> would very much like it if there was an option to have pgindent write
> the changes to disk, but still exit non-zero, e.g. a --write flag that
> could be combined with --check just like --diff and --check can be
> combined with this patch. Currently my pre-commit hook need two
> separate calls to pgindent to both abort the commit and write the
> required changes to disk.
Not sold on this. I don't want pgindent applied automatically to my
uncommitted changes, but I do want a reminder that I forgot to run it.
In any case, as you say it's a different topic.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-19 13:57 Daniel Gustafsson <daniel@yesql.se>
parent: Andrew Dunstan <andrew@dunslane.net>
0 siblings, 1 reply; 31+ messages in thread
From: Daniel Gustafsson @ 2023-12-19 13:57 UTC (permalink / raw)
To: Andrew Dunstan <andrew@dunslane.net>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; Tristan Partin <tristan@neon.tech>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
> On 19 Dec 2023, at 14:51, Andrew Dunstan <andrew@dunslane.net> wrote:
>
> On 2023-12-18 Mo 11:14, Jelte Fennema-Nio wrote:
>> On Mon, 18 Dec 2023 at 13:42, Daniel Gustafsson <daniel@yesql.se> wrote:
>>> I think this is pretty much ready to go, the attached v4 squashes the changes
>>> and fixes the man-page which also needed an update. The referenced Wiki page
>>> will need an edit or two after this goes in, but that's easy enough.
>> One thing I'm wondering: When both --check and --diff are passed,
>> should pgindent still early exit with 2 on the first incorrectly
>> formatted file? Or should it show diffs for all failing files? I'm
>> leaning towards the latter making more sense.
>
> It should show them all.
Agreed.
>> Related (but not required for this patch): For my pre-commit hook I
>> would very much like it if there was an option to have pgindent write
>> the changes to disk, but still exit non-zero, e.g. a --write flag that
>> could be combined with --check just like --diff and --check can be
>> combined with this patch. Currently my pre-commit hook need two
>> separate calls to pgindent to both abort the commit and write the
>> required changes to disk.
>
> Not sold on this. I don't want pgindent applied automatically to my uncommitted changes, but I do want a reminder that I forgot to run it. In any case, as you say it's a different topic.
I think we risk making the tool confusing if we add too many options which can
all be combined to suit every need. The posted v5 seems like a good compromise
I reckon.
Andrew: When applying this, how do we synchronize with the buildfarm to avoid
false negatives due to the BF using the wrong options?
--
Daniel Gustafsson
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-19 15:33 Tristan Partin <tristan@neon.tech>
parent: Tristan Partin <tristan@neon.tech>
1 sibling, 0 replies; 31+ messages in thread
From: Tristan Partin @ 2023-12-19 15:33 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; Jelte Fennema-Nio <postgres@jeltef.nl>; Daniel Gustafsson <daniel@yesql.se>; +Cc: Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon Dec 18, 2023 at 3:18 PM CST, Tristan Partin wrote:
> On Mon Dec 18, 2023 at 10:50 AM CST, Tristan Partin wrote:
> > On Mon Dec 18, 2023 at 10:14 AM CST, Jelte Fennema-Nio wrote:
> > > On Mon, 18 Dec 2023 at 13:42, Daniel Gustafsson <daniel@yesql.se> wrote:
> > > > I think this is pretty much ready to go, the attached v4 squashes the changes
> > > > and fixes the man-page which also needed an update. The referenced Wiki page
> > > > will need an edit or two after this goes in, but that's easy enough.
> > >
> > > One thing I'm wondering: When both --check and --diff are passed,
> > > should pgindent still early exit with 2 on the first incorrectly
> > > formatted file? Or should it show diffs for all failing files? I'm
> > > leaning towards the latter making more sense.
> >
> > Makes sense. Let me iterate on the squashed version of the patch.
>
> Here is an additional patch which implements the behavior you described.
> The first patch is just Daniel's squashed version of my patches.
Assuming all this is good, I now have access to edit the Wiki. The PR
for buildfarm client code is up, and hopefully that PR is correct.
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-19 16:36 Jelte Fennema-Nio <postgres@jeltef.nl>
parent: Tristan Partin <tristan@neon.tech>
1 sibling, 1 reply; 31+ messages in thread
From: Jelte Fennema-Nio @ 2023-12-19 16:36 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Mon, 18 Dec 2023 at 22:18, Tristan Partin <tristan@neon.tech> wrote:
> Here is an additional patch which implements the behavior you described.
> The first patch is just Daniel's squashed version of my patches.
I think we'd still want the early exit behaviour when only --check is
provided. No need to spend time checking more files if you're not
doing anything else.
On Mon, 18 Dec 2023 at 22:34, Tristan Partin <tristan@neon.tech> wrote:
> To me, the two options seem at odds, like you either check or write. How
> would you feel about just capturing the diffs that are printed and
> patch(1)-ing them?
I tried capturing the diffs and patching them, but simply piping the
pgindent output to patch(1) didn't work because the pipe loses the
exit code of pgindent. -o pipefail would help with this, but it's not
available in all shells. Also then it's suddenly unclear if pgident
failed or if patch failed.
Attached are two additional patches (in addition to your unchanged
previous ones). One which adds the --write flag and one which early
exits with --check when neither --write or --diff are provided. The
additional code I added for the --write flag is really minimal IMO.
On Tue, 19 Dec 2023 at 14:51, Andrew Dunstan <andrew@dunslane.net> wrote:
> Not sold on this. I don't want pgindent applied automatically to my
> uncommitted changes, but I do want a reminder that I forgot to run it.
> In any case, as you say it's a different topic.
To be clear, with this patch just passing --check won't apply the
changes automatically. Only when passing both --write and --check will
it write the files.
To clarify my commit workflow is as follows:
git add -p # interactively select all the changes that I want in my commit
git commit
# pre-commit hook fails because of pgindent and "fixes" my files in
place but doesn't add them to the commit yet
git add -p
# I look at all the changes that pgindent make to see if they are
sensible and accept them, if not I find some other way to fix them
git commit
# now commit succeeded
On Tue, 19 Dec 2023 at 14:58, Daniel Gustafsson <daniel@yesql.se> wrote:
> I think we risk making the tool confusing if we add too many options which can
> all be combined to suit every need. The posted v5 seems like a good compromise
> I reckon.
I personally think these options are completely independent. So it's
more confusing to me that they cannot be combined. I updated the help
message in 0003 as well, to describe them as completely independent:
--diff show the changes that need to be made
--check exit with status 2 if any changes need to be made
--write rewrites files that need changes (default
if neither --check/--diff/--write are provided)
PS. prettier (javascript formatter) allows both --check and --write at
the same time to do exactly this
PPS. the help message didn't contain anything about pgindent writing
files by default (i.e. when --check or --diff are not provided)
PPPS. I attached my new pre-commit hook for reference.
Attachments: download all (5 files, .tar.gz)
v6-0002-Print-all-diffs-with-pgindent-check.patch (application/octet-stream, 893B) download
From 00d27a32d35c9fc1050868c1ef92220b4f4fe927 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Mon, 18 Dec 2023 15:14:56 -0600
Subject: [PATCH v6 2/4] Print all diffs with pgindent --check
Previously, only one diff was printed if multiple files were out of
compliance.
---
src/tools/pgindent/pgindent | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index eb2f52f4b9e..0ae4dcddb1c 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -372,6 +372,7 @@ warn "No files to process" unless @files;
process_exclude();
my %processed;
+my $status = 0;
foreach my $source_filename (@files)
{
@@ -427,10 +428,10 @@ foreach my $source_filename (@files)
if ($check)
{
- exit 2;
+ $status = 2;
}
}
}
}
-exit 0;
+exit $status;
--
2.34.1
v6-0001-Rename-non-destructive-modes-in-pgindent.patch (application/octet-stream, 4.4K) download
From 2035560cafaf31e391c40c2e193954df1b666e9d Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Mon, 18 Dec 2023 13:22:12 +0100
Subject: [PATCH v6 1/4] Rename non-destructive modes in pgindent
This renames --silent-diff to --check and --show-diff to --diff,
in order to make the options a little bit more self-explanatory
for developers used to similar formatters/linters. --check and
--diff are also allowed to be combined.
Author: Tristan Partin <tristan@neon.tech>
Discussion: https://postgr.es/m/CXLX2XYTH9S6.140SC6Y61VD88@neon.tech
---
src/tools/pgindent/pgindent | 35 +++++++++++++++++----------------
src/tools/pgindent/pgindent.man | 12 +++++------
2 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index bce63d95daf..eb2f52f4b9e 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -22,8 +22,8 @@ my $indent_opts =
my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
- $indent, $build, $show_diff,
- $silent_diff, $help, @commits,);
+ $indent, $build, $diff,
+ $check, $help, @commits,);
$help = 0;
@@ -34,15 +34,12 @@ my %options = (
"list-of-typedefs=s" => \$typedef_str,
"excludes=s" => \@excludes,
"indent=s" => \$indent,
- "show-diff" => \$show_diff,
- "silent-diff" => \$silent_diff,);
+ "diff" => \$diff,
+ "check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
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")
if (@commits && @ARGV);
@@ -294,7 +291,7 @@ sub run_indent
return $source;
}
-sub show_diff
+sub diff
{
my $indented = shift;
my $source_filename = shift;
@@ -323,8 +320,8 @@ Options:
--list-of-typedefs=STR string containing typedefs, space separated
--excludes=PATH file containing list of filename patterns to ignore
--indent=PATH path to 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
+ --diff show the changes that 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.
EOF
if ($help)
@@ -417,17 +414,21 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if ($silent_diff)
- {
- exit 2;
- }
- elsif ($show_diff)
+ if (!$diff && !$check)
{
- print show_diff($source, $source_filename);
+ write_source($source, $source_filename);
}
else
{
- write_source($source, $source_filename);
+ if ($diff)
+ {
+ print diff($source, $source_filename);
+ }
+
+ if ($check)
+ {
+ exit 2;
+ }
}
}
}
diff --git a/src/tools/pgindent/pgindent.man b/src/tools/pgindent/pgindent.man
index fe411ee699c..caab5cde914 100644
--- a/src/tools/pgindent/pgindent.man
+++ b/src/tools/pgindent/pgindent.man
@@ -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
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
-them. If given instead the --silent-diff option, pgindent will exit with a
-status of 2 if it finds any indent changes are required, but will not
-make the changes or give any other information. This mode is intended for
-possible use in a git pre-commit hook. An example of its use in a git hook
-can be seen at https://wiki.postgresql.org/wiki/Working_with_Git#Using_git_hooks
+them. If given instead the --check option, pgindent will exit with a status of
+2 if it finds any indent changes are required, but will not make the changes.
+This mode is intended for possible use in a git pre-commit hook. The --check
+and --diff options can be combined. An example of its use in a git hook can be
+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
case only these files will be changed, and nothing else will be touched.
base-commit: 2a607fb822a2ad8f3a2cc714871283ad8cdf71c4
--
2.34.1
v6-0003-Add-write-flag-to-pgindent.patch (application/octet-stream, 2.3K) download
From 5ab13f2f4887fa7e39676811e3eda8cf6b6d98a3 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <jelte.fennema@microsoft.com>
Date: Tue, 19 Dec 2023 16:51:23 +0100
Subject: [PATCH v6 3/4] Add --write flag to pgindent
The --write flag can be used to still write files even if --check or
--diff are provided. This allows for easy and efficient integration into
some pre-commit hook workflows.
---
src/tools/pgindent/pgindent | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 0ae4dcddb1c..10f8cbaeabf 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -23,7 +23,7 @@ my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
$indent, $build, $diff,
- $check, $help, @commits,);
+ $check, $write, $help, @commits,);
$help = 0;
@@ -35,9 +35,15 @@ my %options = (
"excludes=s" => \@excludes,
"indent=s" => \$indent,
"diff" => \$diff,
+ "write" => \$write,
"check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
+if (!$check && !$diff)
+{
+ $write = 1;
+}
+
usage() if $help;
usage("Cannot use --commit with command line file list")
@@ -320,8 +326,9 @@ Options:
--list-of-typedefs=STR string containing typedefs, space separated
--excludes=PATH file containing list of filename patterns to ignore
--indent=PATH path to pg_bsd_indent program
- --diff show the changes that would be made
- --check exit with status 2 if any changes would be made
+ --diff show the changes that need to be made
+ --check exit with status 2 if any changes need to be made
+ --write rewrites files that need changes (default if neither --check/--diff/--write are provided)
The --excludes and --commit options can be given more than once.
EOF
if ($help)
@@ -415,21 +422,17 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if (!$diff && !$check)
+ if ($write)
{
write_source($source, $source_filename);
}
- else
+ if ($diff)
+ {
+ print diff($source, $source_filename);
+ }
+ if ($check)
{
- if ($diff)
- {
- print diff($source, $source_filename);
- }
-
- if ($check)
- {
- $status = 2;
- }
+ $status = 2;
}
}
}
--
2.34.1
v6-0004-Early-exit-with-pgindent-check-when-possible.patch (application/octet-stream, 1008B) download
From 289490728f230c55f7c9f90389c80289c90fbd6c Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <jelte.fennema@microsoft.com>
Date: Tue, 19 Dec 2023 16:57:45 +0100
Subject: [PATCH v6 4/4] Early exit with pgindent --check when possible
No need to check all the files if we only care about pgindent its exit
code. We can fail at the first file to be done quicker.
---
src/tools/pgindent/pgindent | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 10f8cbaeabf..23bb3eb6ae5 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -432,7 +432,17 @@ foreach my $source_filename (@files)
}
if ($check)
{
- $status = 2;
+ if ($write || $diff)
+ {
+ # We don't want to exit immediately, because we
+ # want to write and/or diff all the files
+ $status = 2;
+ }
+ else
+ {
+ # We're just checking, so we can exit immediately
+ exit 2;
+ }
}
}
}
--
2.34.1
pre-commit (application/octet-stream, 1022B) download
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-19 16:54 Tristan Partin <tristan@neon.tech>
parent: Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 1 reply; 31+ messages in thread
From: Tristan Partin @ 2023-12-19 16:54 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Tue Dec 19, 2023 at 10:36 AM CST, Jelte Fennema-Nio wrote:
> On Mon, 18 Dec 2023 at 22:18, Tristan Partin <tristan@neon.tech> wrote:
> > Here is an additional patch which implements the behavior you described.
> > The first patch is just Daniel's squashed version of my patches.
>
> I think we'd still want the early exit behaviour when only --check is
> provided. No need to spend time checking more files if you're not
> doing anything else.
Good point. Patch looks good.
> On Mon, 18 Dec 2023 at 22:34, Tristan Partin <tristan@neon.tech> wrote:
> > To me, the two options seem at odds, like you either check or write. How
> > would you feel about just capturing the diffs that are printed and
> > patch(1)-ing them?
>
> I tried capturing the diffs and patching them, but simply piping the
> pgindent output to patch(1) didn't work because the pipe loses the
> exit code of pgindent. -o pipefail would help with this, but it's not
> available in all shells. Also then it's suddenly unclear if pgident
> failed or if patch failed.
I was envisioning something along the lines of:
pgindent --check --diff > patches.txt
status=$?
patch <patches.txt # no idea if this works, or if you need a for loop with manual parsing
exit $status
--
Tristan Partin
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-20 16:05 Andrew Dunstan <andrew@dunslane.net>
parent: Daniel Gustafsson <daniel@yesql.se>
0 siblings, 1 reply; 31+ messages in thread
From: Andrew Dunstan @ 2023-12-20 16:05 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; Tristan Partin <tristan@neon.tech>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On 2023-12-19 Tu 08:57, Daniel Gustafsson wrote:
>> On 19 Dec 2023, at 14:51, Andrew Dunstan <andrew@dunslane.net> wrote:
>>
>> On 2023-12-18 Mo 11:14, Jelte Fennema-Nio wrote:
>>> On Mon, 18 Dec 2023 at 13:42, Daniel Gustafsson <daniel@yesql.se> wrote:
>>>> I think this is pretty much ready to go, the attached v4 squashes the changes
>>>> and fixes the man-page which also needed an update. The referenced Wiki page
>>>> will need an edit or two after this goes in, but that's easy enough.
>>> One thing I'm wondering: When both --check and --diff are passed,
>>> should pgindent still early exit with 2 on the first incorrectly
>>> formatted file? Or should it show diffs for all failing files? I'm
>>> leaning towards the latter making more sense.
>> It should show them all.
> Agreed.
>
>>> Related (but not required for this patch): For my pre-commit hook I
>>> would very much like it if there was an option to have pgindent write
>>> the changes to disk, but still exit non-zero, e.g. a --write flag that
>>> could be combined with --check just like --diff and --check can be
>>> combined with this patch. Currently my pre-commit hook need two
>>> separate calls to pgindent to both abort the commit and write the
>>> required changes to disk.
>> Not sold on this. I don't want pgindent applied automatically to my uncommitted changes, but I do want a reminder that I forgot to run it. In any case, as you say it's a different topic.
> I think we risk making the tool confusing if we add too many options which can
> all be combined to suit every need. The posted v5 seems like a good compromise
> I reckon.
>
> Andrew: When applying this, how do we synchronize with the buildfarm to avoid
> false negatives due to the BF using the wrong options?
The only buildfarm animal involved here is koel, which I run, so the
simplest way will be for me to commit the core patch and adjust the
buildfarm code at the same time.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-20 22:38 Andrew Dunstan <andrew@dunslane.net>
parent: Andrew Dunstan <andrew@dunslane.net>
0 siblings, 0 replies; 31+ messages in thread
From: Andrew Dunstan @ 2023-12-20 22:38 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; Tristan Partin <tristan@neon.tech>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On 2023-12-20 We 11:05, Andrew Dunstan wrote:
>
> On 2023-12-19 Tu 08:57, Daniel Gustafsson wrote:
>> The posted v5 seems like a good compromise
>> I reckon.
>>
>> Andrew: When applying this, how do we synchronize with the buildfarm
>> to avoid
>> false negatives due to the BF using the wrong options?
>
>
> The only buildfarm animal involved here is koel, which I run, so the
> simplest way will be for me to commit the core patch and adjust the
> buildfarm code at the same time.
>
>
V5 seems to be the consensus. I went with that, but added in logic to
exit the loop early for --check if we're not also doing --diff.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: Add --check option to pgindent
@ 2023-12-21 10:58 Jelte Fennema-Nio <postgres@jeltef.nl>
parent: Tristan Partin <tristan@neon.tech>
0 siblings, 0 replies; 31+ messages in thread
From: Jelte Fennema-Nio @ 2023-12-21 10:58 UTC (permalink / raw)
To: Tristan Partin <tristan@neon.tech>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Andrew Dunstan <andrew@dunslane.net>; Alvaro Herrera <alvherre@alvh.no-ip.org>; Tom Lane <tgl@sss.pgh.pa.us>; Euler Taveira <euler@eulerto.com>; Michael Banck <mbanck@gmx.net>; pgsql-hackers
On Tue, 19 Dec 2023 at 17:54, Tristan Partin <tristan@neon.tech> wrote:
> I was envisioning something along the lines of:
>
> pgindent --check --diff > patches.txt
> status=$?
> patch <patches.txt # no idea if this works, or if you need a for loop with manual parsing
> exit $status
Okay, I got a working version. And I updated the pre-commit hook on
the wiki accordingly.
^ permalink raw reply [nested|flat] 31+ messages in thread
end of thread, other threads:[~2023-12-21 10:58 UTC | newest]
Thread overview: 31+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-12-12 00:09 Add --check option to pgindent Tristan Partin <tristan@neon.tech>
2023-12-12 00:21 ` Daniel Gustafsson <daniel@yesql.se>
2023-12-12 10:18 ` Daniel Gustafsson <daniel@yesql.se>
2023-12-12 10:28 ` Michael Banck <mbanck@gmx.net>
2023-12-12 11:47 ` Euler Taveira <euler@eulerto.com>
2023-12-12 15:18 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-12-12 15:30 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2023-12-13 20:46 ` Andrew Dunstan <andrew@dunslane.net>
2023-12-14 16:53 ` Tristan Partin <tristan@neon.tech>
2023-12-15 14:18 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2023-12-15 15:43 ` Tristan Partin <tristan@neon.tech>
2023-12-18 12:41 ` Daniel Gustafsson <daniel@yesql.se>
2023-12-18 13:56 ` Euler Taveira <euler@eulerto.com>
2023-12-18 15:45 ` Tristan Partin <tristan@neon.tech>
2023-12-18 15:45 ` Tristan Partin <tristan@neon.tech>
2023-12-18 15:59 ` Matthias van de Meent <boekewurm+postgres@gmail.com>
2023-12-18 16:14 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2023-12-18 16:15 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2023-12-18 16:50 ` Tristan Partin <tristan@neon.tech>
2023-12-18 17:21 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2023-12-18 21:34 ` Tristan Partin <tristan@neon.tech>
2023-12-18 21:18 ` Tristan Partin <tristan@neon.tech>
2023-12-19 15:33 ` Tristan Partin <tristan@neon.tech>
2023-12-19 16:36 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2023-12-19 16:54 ` Tristan Partin <tristan@neon.tech>
2023-12-21 10:58 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2023-12-19 13:51 ` Andrew Dunstan <andrew@dunslane.net>
2023-12-19 13:57 ` Daniel Gustafsson <daniel@yesql.se>
2023-12-20 16:05 ` Andrew Dunstan <andrew@dunslane.net>
2023-12-20 22:38 ` Andrew Dunstan <andrew@dunslane.net>
2023-12-12 15:26 ` Tristan Partin <tristan@neon.tech>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox