Re: [PATCH 1/1] checkpatch: check for subject uniqueness in git repository.
From: Fabian Frederick
Date: Tue Sep 16 2014 - 12:15:25 EST
> On 16 September 2014 at 05:22 Joe Perches <joe@xxxxxxxxxxx> wrote:
>
>
> 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++;
>
>
Perfect ! :)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/