diff mbox

scripts: add checkmaintainers.py

Message ID 1355866399.3297.2.camel@joe-AO722 (mailing list archive)
State New, archived
Headers show

Commit Message

Joe Perches Dec. 18, 2012, 9:33 p.m. UTC
On Tue, 2012-12-18 at 21:47 +0100, Borislav Petkov wrote:
> Oh well, enough games for today.

Maybe try this tomorrow?

Comments

Borislav Petkov Dec. 19, 2012, 3:07 p.m. UTC | #1
On Tue, Dec 18, 2012 at 01:33:19PM -0800, Joe Perches wrote:
> On Tue, 2012-12-18 at 21:47 +0100, Borislav Petkov wrote:
> > Oh well, enough games for today.
> 
> Maybe try this tomorrow?

$ git diff --cached HEAD -- | ./scripts/checkpatch.pl --strict -
Use of uninitialized value $herecurr in concatenation (.) or string at ./scripts/checkpatch.pl line 1333.
CHECK: Patch renames arch/x86/Kconfig to arch/x86/Kconfig.old, update MAINTAINERS?

yes, except the warning.

$ git commit -a
arch/x86/Kconfig.old:451: trailing whitespace.
+         Internet Device(MID) platform.

This doesn't seem to work although I have the same pre-commit hook as
the above line: " git diff --cached HEAD -- | ./scripts/checkpatch.pl --strict -"

$ git diff --cached HEAD
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig.old
similarity index 100%
rename from arch/x86/Kconfig
rename to arch/x86/Kconfig.old

and this is probably the reason - you said checkpatch needs an unified
diff after the initial lines.

So this is getting closer except checkpatch needs to still warn in the
case where there's no unified diff following *but* a single file rename.

Thanks.
diff mbox

Patch

 scripts/checkpatch.pl |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 725c596..adc8de1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1317,6 +1317,19 @@  sub check_absolute_file {
 	}
 }
 
+sub check_filenames_changed {
+    my ($oldfile, $newfile, $herecurr) = @_;
+
+    return if ($oldfile eq $newfile);
+
+    my $action = "renames $oldfile to $newfile";
+    $action = "creates file $newfile" if ($oldfile =~ m@dev/null@);
+    $action = "deletes file $oldfile" if ($newfile =~ m@dev/null@);
+
+    CHK("MAINTAINERS",
+	"Patch $action, update MAINTAINERS?\n" . $herecurr);
+}
+
 sub pos_last_openparen {
 	my ($line) = @_;
 
@@ -1379,6 +1392,9 @@  sub process {
 	# Trace the real file/line as we go.
 	my $realfile = '';
 	my $realline = 0;
+	my $modifiedfile = '';
+	my $gitrealfile = '';
+	my $gitmodifiedfile = '';
 	my $realcnt = 0;
 	my $here = '';
 	my $in_comment = 0;
@@ -1536,10 +1552,17 @@  sub process {
 		$here = "#$realline: " if ($file);
 
 		# extract the filename as it passes
-		if ($line =~ /^diff --git.*?(\S+)$/) {
-			$realfile = $1;
+		if ($line =~ /^diff --git\s+(\S+)\s+(\S+)$/) {
+			$modifiedfile = $1;
+			$realfile = $2;
+			$modifiedfile =~ s@^([^/]*)/@@;
 			$realfile =~ s@^([^/]*)/@@;
+
+			$gitmodifiedfile = $modifiedfile;
+			$gitrealfile = $realfile;
 			$in_commit_log = 0;
+			check_filenames_changed($gitmodifiedfile, $gitrealfile);
+
 		} elsif ($line =~ /^\+\+\+\s+(\S+)/) {
 			$realfile = $1;
 			$realfile =~ s@^([^/]*)/@@;
@@ -1556,6 +1579,19 @@  sub process {
 				ERROR("MODIFIED_INCLUDE_ASM",
 				      "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
 			}
+
+			if ($modifiedfile ne $gitmodifiedfile ||
+			    $realfile ne $gitrealfile) {
+				check_filenames_changed($modifiedfile, $realfile);
+				$gitmodifiedfile = '';
+				$gitrealfile = '';
+			}
+
+			next;
+		} elsif ($line =~ /^\-\-\-\s+(\S+)/) {
+			$modifiedfile = $1;
+			$modifiedfile =~ s@^([^/]*)/@@;
+			$in_commit_log = 0;
 			next;
 		}