Skip to content

Commit f5f6132

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: allow not using -f with files that are in git
If a file exists in git and checkpatch is used without the -f flag for scanning a file, then checkpatch will scan the file assuming it's a patch and emit: ERROR: Does not appear to be a unified-diff format patch Change the behavior to assume the -f flag if the file exists in git. [[email protected]: fix git "fatal" warning if file argument outside kernel tree] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Joe Perches <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Julia Lawall <[email protected]> Cc: Rasmus Villemoes <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 99ca38c commit f5f6132

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

scripts/checkpatch.pl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,16 @@ sub seed_camelcase_includes {
974974
}
975975
}
976976

977+
sub git_is_single_file {
978+
my ($filename) = @_;
979+
980+
return 0 if ((which("git") eq "") || !(-e "$gitroot"));
981+
982+
my $output = `${git_command} ls-files -- $filename 2>/dev/null`;
983+
my $count = $output =~ tr/\n//;
984+
return $count eq 1 && $output =~ m{^${filename}$};
985+
}
986+
977987
sub git_commit_info {
978988
my ($commit, $id, $desc) = @_;
979989

@@ -1047,6 +1057,9 @@ sub git_commit_info {
10471057
$allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"};
10481058
for my $filename (@ARGV) {
10491059
my $FILE;
1060+
my $is_git_file = git_is_single_file($filename);
1061+
my $oldfile = $file;
1062+
$file = 1 if ($is_git_file);
10501063
if ($git) {
10511064
open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
10521065
die "$P: $filename: git format-patch failed - $!\n";
@@ -1091,6 +1104,7 @@ sub git_commit_info {
10911104
@modifierListFile = ();
10921105
@typeListFile = ();
10931106
build_types();
1107+
$file = $oldfile if ($is_git_file);
10941108
}
10951109

10961110
if (!$quiet) {

0 commit comments

Comments
 (0)