summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Dunstan2023-02-12 13:43:44 +0000
committerAndrew Dunstan2023-02-12 13:51:01 +0000
commitdab07e8c6896df3129bc153ead1f107e695652ee (patch)
tree4e6d2e0cd8465908c8d17dc530a038f1ab12f996 /src
parent10a082bf72150f49c34fcf152565c77d80f31a9c (diff)
pgindent: filter files for the --commit option
per gripe from Shi Yu, solution from Jelte Fennema Also add a check that the file exists, and issue a warning if it doesn't. As an efficiency measure, avoid processing any file more than once. Discussion: https://postgr.es/m/TYAPR01MB6315B86619944D4A6B56842DFDDE9@TYAPR01MB6315.jpnprd01.prod.outlook.com
Diffstat (limited to 'src')
-rwxr-xr-xsrc/tools/pgindent/pgindent14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 07970f758c2..a793971e078 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -444,7 +444,7 @@ File::Find::find({wanted => $wanted}, @ARGV) if @ARGV;
foreach my $commit (@commits)
{
my $prev="$commit~";
- my @affected=`git diff-tree --no-commit-id --name-only -r $commit $prev`;
+ my @affected=`git diff --diff-filter=ACMR --name-only $prev $commit`;
die "git error" if $?;
chomp(@affected);
push(@files,@affected);
@@ -453,11 +453,23 @@ foreach my $commit (@commits)
# remove excluded files from the file list
process_exclude();
+my %processed;
+
foreach my $source_filename (@files)
{
+ # skip duplicates
+ next if $processed{$source_filename};
+ $processed{$source_filename} = 1;
+
# ignore anything that's not a .c or .h file
next unless $source_filename =~ /\.[ch]$/;
+ # don't try to indent a file that doesn't exist
+ unless (-f $source_filename)
+ {
+ warn "Could not find $source_filename";
+ next;
+ }
# Automatically ignore .c and .h files that correspond to a .y or .l
# file. indent tends to get badly confused by Bison/flex output,
# and there's no value in indenting derived files anyway.