checkpatch: allow not using -f with files that are in git
[linux-2.6-microblaze.git] / scripts / checkpatch.pl
index 5fe8762..360ae4b 100755 (executable)
@@ -974,6 +974,16 @@ sub seed_camelcase_includes {
        }
 }
 
+sub git_is_single_file {
+       my ($filename) = @_;
+
+       return 0 if ((which("git") eq "") || !(-e "$gitroot"));
+
+       my $output = `${git_command} ls-files -- $filename 2>/dev/null`;
+       my $count = $output =~ tr/\n//;
+       return $count eq 1 && $output =~ m{^${filename}$};
+}
+
 sub git_commit_info {
        my ($commit, $id, $desc) = @_;
 
@@ -1047,6 +1057,9 @@ my $vname;
 $allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"};
 for my $filename (@ARGV) {
        my $FILE;
+       my $is_git_file = git_is_single_file($filename);
+       my $oldfile = $file;
+       $file = 1 if ($is_git_file);
        if ($git) {
                open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
                        die "$P: $filename: git format-patch failed - $!\n";
@@ -1091,6 +1104,7 @@ for my $filename (@ARGV) {
        @modifierListFile = ();
        @typeListFile = ();
        build_types();
+       $file = $oldfile if ($is_git_file);
 }
 
 if (!$quiet) {