public inbox for [email protected]
help / color / mirror / Atom feedFrom: Andrew Dunstan <[email protected]>
To: Jelte Fennema <[email protected]>
Cc: 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: Wed, 8 Feb 2023 07:41:59 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAGECzQRJrcoxozHh=BRTdLrirFui-3nvdRZru7GGa4F9HJV2Rw@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+TgmoYTg4avVbkzhhQi3Z-HoxsAvtD=tZiSdWZU9avF_2ouZA@mail.gmail.com>
<[email protected]>
<[email protected]>
<CAGECzQRJrcoxozHh=BRTdLrirFui-3nvdRZru7GGa4F9HJV2Rw@mail.gmail.com>
On 2023-02-07 Tu 12:21, Jelte Fennema wrote:
>> On Mon, Feb 6, 2023 at 10:21 AM Andrew Dunstan<[email protected]> wrote:
>>
>> Here's a quick patch for 1 and 3. Would also need to adjust the docco.
>>
>>
>>
>> This time with patch.
> When supplying the --commit flag it still formats all files for me. I
> was able to fix that by replacing:
> # no non-option arguments given. so do everything in the current directory
> $code_base ||= '.' unless @ARGV;
>
> with:
> # no files, dirs or commits given. so do everything in the current directory
> $code_base ||= '.' unless @ARGV || @commits;
Yeah, thanks for testing. Here's a new patch with that change and the
comment adjusted.
>
> Does the code-base flag still make sense if you can simply pass a
> directory as regular args now?
Probably not. I'll look into removing it.
cheers
andrew
--
Andrew Dunstan
EDB:https://www.enterprisedb.com
Attachments:
[text/x-patch] pgindent-directory+git-enhancements-v2.patch (3.7K, ../[email protected]/3-pgindent-directory+git-enhancements-v2.patch)
download | inline diff:
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 56640e576a..34fb7d604d 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -23,12 +23,14 @@ my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, $code_base,
@excludes, $indent, $build,
- $show_diff, $silent_diff, $help);
+ $show_diff, $silent_diff, $help,
+ @commits,);
$help = 0;
my %options = (
"help" => \$help,
+ "commit=s" => \@commits,
"typedefs=s" => \$typedefs_file,
"list-of-typedefs=s" => \$typedef_str,
"code-base=s" => \$code_base,
@@ -44,6 +46,9 @@ 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));
+
run_build($code_base) if ($build);
# command line option wins, then environment (which is how --build sets it) ,
@@ -53,8 +58,9 @@ $typedefs_file ||= $ENV{PGTYPEDEFS};
# build mode sets PGINDENT
$indent ||= $ENV{PGINDENT} || $ENV{INDENT} || "pg_bsd_indent";
-# no non-option arguments given. so do everything in the current directory
-$code_base ||= '.' unless @ARGV;
+# if no non-option arguments or commits are given, default to looking in the
+# current directory
+$code_base ||= '.' unless (@ARGV || @commits);
my $sourcedir = locate_sourcedir();
@@ -388,6 +394,7 @@ Usage:
pgindent [OPTION]... [FILE]...
Options:
--help show this message and quit
+ --commit=gitref use files modified by the named commit
--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
@@ -396,7 +403,7 @@ Options:
--build build the 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
-The --excludes option can be given more than once.
+The --excludes and --commit options can be given more than once.
EOF
if ($help)
{
@@ -412,27 +419,38 @@ EOF
# main
-# get the list of files under code base, if it's set
-File::Find::find(
- {
- wanted => sub {
- my ($dev, $ino, $mode, $nlink, $uid, $gid);
- (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))
- && -f _
- && /^.*\.[ch]\z/s
- && push(@files, $File::Find::name);
- }
- },
- $code_base) if $code_base;
-
$filtered_typedefs_fh = load_typedefs();
check_indent();
-# any non-option arguments are files to be processed
-push(@files, @ARGV);
+build_clean($code_base) if $build;
-# the exclude list applies to command line arguments as well as found files
+my $wanted = sub
+{
+ my ($dev, $ino, $mode, $nlink, $uid, $gid);
+ (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))
+ && -f _
+ && /^.*\.[ch]\z/s
+ && push(@files, $File::Find::name);
+};
+
+# get the list of files under code base, if it's set
+File::Find::find({wanted => $wanted }, $code_base) if $code_base;
+
+# any non-option arguments are files or directories to be processed
+File::Find::find({wanted => $wanted}, @ARGV) if @ARGV;
+
+# process named commits by comparing each with their immediate ancestor
+foreach my $commit (@commits)
+{
+ my $prev="$commit~";
+ my @affected=`git diff-tree --no-commit-id --name-only -r $commit $prev`;
+ die "git error" if $?;
+ chomp(@affected);
+ push(@files,@affected);
+}
+
+# remove excluded files from the file list
process_exclude();
foreach my $source_filename (@files)
@@ -481,6 +499,4 @@ foreach my $source_filename (@files)
}
}
-build_clean($code_base) if $build;
-
exit 0;
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