On 2023-02-10 Fr 04:25, Jelte Fennema wrote:
Ah yes, I had seen that when I read the initial --commit patch but
then forgot about it when the flag didn't work at all when I tried it.

Attached is a patch that fixes the issue. And also implements the
--dirty and --staged flags in pgindent that Robert Haas requested.


[please don't top-post]


I don't think just adding a diff filter is really a sufficient fix. The file might have been deleted since the commit(s) in question. Here's a more general fix for missing files.


cheers


andrew


--
Andrew Dunstan
EDB:https://www.enterprisedb.com
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 07970f758c..64284e7ea2 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);
@@ -458,6 +458,12 @@ foreach my $source_filename (@files)
 	# 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.

Reply via email to