public inbox for [email protected]
help / color / mirror / Atom feedFrom: Andrew Dunstan <[email protected]>
To: Jelte Fennema <[email protected]>
To: Robert Haas <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: Justin Pryzby <[email protected]>
Cc: Andres Freund <[email protected]>
Cc: Noah Misch <[email protected]>
Cc: Peter Geoghegan <[email protected]>
Cc: Bruce Momjian <[email protected]>
Cc: Magnus Hagander <[email protected]>
Cc: Alvaro Herrera <[email protected]>
Cc: Stephen Frost <[email protected]>
Cc: Jesse Zhang <[email protected]>
Cc: [email protected]
Subject: Re: run pgindent on a regular basis / scripted manner
Date: Fri, 10 Feb 2023 09:26:50 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAGECzQSvgQAXwstka3LrX2c=rm5ypuKh8=vu-Rh3u9Eerh0jpg@mail.gmail.com>
References: <CAH2-Wzm0niYBPcN6eX3PzHABfj0dE3fwifo5bdturvMp=9FGqw@mail.gmail.com>
<[email protected]>
<CAGECzQRYjHdNQ-Bq2yrBb-8s3Pjx7pfvYPDdNv9tcvDcscDhbg@mail.gmail.com>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<CA+TgmoY59Ksso81RNLArNxj0a7xaqV_F_u7gSMHbgdc2kG5Vpw@mail.gmail.com>
<[email protected]>
<CA+TgmobWzN_P3WCdDR-sO9EzVWMFice8oViVCFUW+0T0mXiZKg@mail.gmail.com>
<CAGECzQSvgQAXwstka3LrX2c=rm5ypuKh8=vu-Rh3u9Eerh0jpg@mail.gmail.com>
On 2023-02-07 Tu 11:32, Jelte Fennema wrote:
> On Tue, 7 Feb 2023 at 17:11, Robert Haas<[email protected]> wrote:
>> I don't know if that works or not, but it does seem plausible, at
>> least. My idea would have been to use the --name-status option, which
>> works for both git diff and git show. You just look and see which
>> lines in the output start with M or A and then take the file names
>> from those lines.
> If you add `--diff-filter=ACMR`, then git diff/show will only show
> Added, Copied, Modified, and Renamed files.
>
> The pre-commit hook that Andrew added to the wiki uses that in
> combination with --name-only to get the list of files that you want to
> check on commit:
> https://wiki.postgresql.org/wiki/Working_with_Git#Using_git_hooks
OK, here's a patch based on Robert's and Jelte's ideas.
cheers
andrew
--
Andrew Dunstan
EDB:https://www.enterprisedb.com
Attachments:
[text/x-patch] pgindent-dirty-cached.patch (2.2K, ../[email protected]/3-pgindent-dirty-cached.patch)
download | inline diff:
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 07970f758c..c9f42302c9 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -24,13 +24,15 @@ my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, $code_base,
@excludes, $indent, $build,
$show_diff, $silent_diff, $help,
- @commits,);
+ @commits, $dirty, $cached);
$help = 0;
my %options = (
"help" => \$help,
"commit=s" => \@commits,
+ "dirty" => \$dirty,
+ "cached" => \$cached,
"typedefs=s" => \$typedefs_file,
"list-of-typedefs=s" => \$typedef_str,
"code-base=s" => \$code_base,
@@ -46,8 +48,11 @@ usage() if $help;
usage("Cannot have both --silent-diff and --show-diff")
if $silent_diff && $show_diff;
-usage("Cannot use --commit with --code-base or command line file list")
- if (@commits && ($code_base || @ARGV));
+usage("Cannot use --commit, --dirty or --cached with --code-base or command line file list")
+ if (($dirty || $cached || @commits) && ($code_base || @ARGV));
+
+usage( "Cannot use --dirty or --cached with --commit")
+ if (($dirty || $cached) && @commits);
run_build($code_base) if ($build);
@@ -395,6 +400,8 @@ pgindent [OPTION]... [FILE]...
Options:
--help show this message and quit
--commit=gitref use files modified by the named commit
+ --dirty use modified files under current directory
+ --cached use staged files under current directory
--typedefs=FILE file containing a list of typedefs
--list-of-typedefs=STR string containing typedefs, space separated
--code-base=DIR path to the base of PostgreSQL source code
@@ -450,6 +457,19 @@ foreach my $commit (@commits)
push(@files,@affected);
}
+# look for dirty / cached files under the CWD
+if ($dirty || $cached)
+{
+ my $gitcmd = "git diff --diff-filter=ACMR --name-only";
+ $gitcmd .= " --cached" if ($cached && !$dirty);
+ $gitcmd .= " HEAD" if ($dirty && $cached);
+ $gitcmd .= " -- .";
+ my @affected=`$gitcmd`;
+ die "git error" if $?;
+ chomp(@affected);
+ push(@files,@affected);
+}
+
# remove excluded files from the file list
process_exclude();
view thread (142+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: run pgindent on a regular basis / scripted manner
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox