mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Fabian Frederick <fabf@skynet.be>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 1/1] checkpatch: check for subject uniqueness in git repository.
Date: Mon, 15 Sep 2014 20:22:49 -0700	[thread overview]
Message-ID: <1410837769.18787.40.camel@joe-AO725> (raw)
In-Reply-To: <1410806637-3510-1-git-send-email-fabf@skynet.be>

On Mon, 2014-09-15 at 20:43 +0200, Fabian Frederick wrote:
> Adding patch subject uniqueness check in checkpatch --strict mode.
> See Documentation/SubmittingPatches/globally-unique identifier.

Perhaps something like this?
---
 scripts/checkpatch.pl | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0c520f7..e19c40b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -622,6 +622,27 @@ sub git_commit_info {
 	return ($id, $desc);
 }
 
+my @git_commits = ();
+my @previous_subjects = ();
+
+sub check_subject_duplication {
+	my ($subject) = @_;
+
+	if ($check && $#git_commits < 1 && which("git") && -e ".git") {
+		my $output = `git log --no-color --format='%H %s' 2>&1`;
+		$output =~ s/^\s*//gm;
+		@git_commits = split("\n", $output);
+	}
+
+	return 1 if (grep(/^[a-f0-9]{40,40} $subject$/, @git_commits));
+
+	return 2 if (grep(/^$subject$/, @previous_subjects));
+
+	push(@previous_subjects, $subject);
+
+	return 0;
+}
+
 $chk_signoff = 0 if ($file);
 
 my @rawlines = ();
@@ -1264,6 +1285,20 @@ sub raw_line {
 	return $line;
 }
 
+sub get_complete_header {
+	my ($linenr) = @_;
+
+	my $offset = $linenr - 1;
+
+	my $line = $rawlines[$offset++];
+	while (defined $rawlines[$offset] &&
+	       $rawlines[$offset] =~ /\s(\S.*)$/) {
+		$line .= $rawlines[$offset++];
+	}
+
+	return $line;
+}
+
 sub cat_vet {
 	my ($vet) = @_;
 	my ($res, $coded);
@@ -2047,6 +2082,23 @@ sub process {
 			}
 		}
 
+# Check git commit and patch subject duplication
+		if ($in_header_lines && $line =~ /^Subject:/) {
+			my $subject = get_complete_header($linenr);
+			if ($subject =~ /^Subject:\s*(?:\[[^\]]*\])?\s*(.*)$/) {
+				$subject = $1;
+			}
+
+			my $subject_dup = check_subject_duplication($subject);
+			if ($subject_dup == 1) {
+				CHK("NOT_UNIQUE_SUBJECT",
+				    "Identical git commit subject found\n" . $herecurr);
+			} elsif ($subject_dup == 2) {
+				CHK("NOT_UNIQUE_SUBJECT",
+				    "Identical patch commit subject found\n" . $herecurr);
+			}
+		}
+
 # Check the patch for a signoff:
 		if ($line =~ /^\s*signed-off-by:/i) {
 			$signoff++;



  parent reply	other threads:[~2014-09-16  3:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-15 18:43 Fabian Frederick
2014-09-15 21:02 ` Joe Perches
2014-09-16  3:22 ` Joe Perches [this message]
2014-09-16 16:15   ` Fabian Frederick
2014-09-16 16:31     ` Joe Perches
2014-09-20 10:31       ` Fabian Frederick
2014-09-20 16:07         ` Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1410837769.18787.40.camel@joe-AO725 \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=fabf@skynet.be \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®