lkml.org 
[lkml]   [2014]   [Sep]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/1] checkpatch: check for subject uniqueness in git repository.


> On 16 September 2014 at 05:22 Joe Perches <joe@perches.com> 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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2014-09-16 18:41    [W:0.241 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site