Commit d311cd44545f2f69749c68d6723360b4cc21cd02
Committed by
Linus Torvalds
1 parent
e367455a9f
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
checkpatch: add test for commit id formatting style in commit log
Commit logs have various forms of commit id references. Try to standardize on a 12 character long lower case commit id along with a description of parentheses and the quoted subject line. ie: commit 0123456789ab ("commit description") If git and a git tree exists, look up the commit id and emit the appropriate line as part of the message. Signed-off-by: Joe Perches <joe@perches.com> Requested-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 54 additions and 0 deletions Side-by-side Diff
scripts/checkpatch.pl
... | ... | @@ -550,6 +550,34 @@ |
550 | 550 | } |
551 | 551 | } |
552 | 552 | |
553 | +sub git_commit_info { | |
554 | + my ($commit, $id, $desc) = @_; | |
555 | + | |
556 | + return ($id, $desc) if ((which("git") eq "") || !(-e ".git")); | |
557 | + | |
558 | + my $output = `git log --no-color --format='%H %s' -1 $commit 2>&1`; | |
559 | + $output =~ s/^\s*//gm; | |
560 | + my @lines = split("\n", $output); | |
561 | + | |
562 | + if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) { | |
563 | +# Maybe one day convert this block of bash into something that returns | |
564 | +# all matching commit ids, but it's very slow... | |
565 | +# | |
566 | +# echo "checking commits $1..." | |
567 | +# git rev-list --remotes | grep -i "^$1" | | |
568 | +# while read line ; do | |
569 | +# git log --format='%H %s' -1 $line | | |
570 | +# echo "commit $(cut -c 1-12,41-)" | |
571 | +# done | |
572 | + } elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./) { | |
573 | + } else { | |
574 | + $id = substr($lines[0], 0, 12); | |
575 | + $desc = substr($lines[0], 41); | |
576 | + } | |
577 | + | |
578 | + return ($id, $desc); | |
579 | +} | |
580 | + | |
553 | 581 | $chk_signoff = 0 if ($file); |
554 | 582 | |
555 | 583 | my @rawlines = (); |
... | ... | @@ -674,6 +702,18 @@ |
674 | 702 | return $formatted_email; |
675 | 703 | } |
676 | 704 | |
705 | +sub which { | |
706 | + my ($bin) = @_; | |
707 | + | |
708 | + foreach my $path (split(/:/, $ENV{PATH})) { | |
709 | + if (-e "$path/$bin") { | |
710 | + return "$path/$bin"; | |
711 | + } | |
712 | + } | |
713 | + | |
714 | + return ""; | |
715 | +} | |
716 | + | |
677 | 717 | sub which_conf { |
678 | 718 | my ($conf) = @_; |
679 | 719 | |
... | ... | @@ -1956,6 +1996,20 @@ |
1956 | 1996 | if ($in_commit_log && $line =~ /^\s*change-id:/i) { |
1957 | 1997 | ERROR("GERRIT_CHANGE_ID", |
1958 | 1998 | "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); |
1999 | + } | |
2000 | + | |
2001 | +# Check for improperly formed commit descriptions | |
2002 | + if ($in_commit_log && | |
2003 | + $line =~ /\bcommit\s+[0-9a-f]{5,}/i && | |
2004 | + $line !~ /\b[Cc]ommit [0-9a-f]{12,16} \("/) { | |
2005 | + $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i; | |
2006 | + my $init_char = $1; | |
2007 | + my $orig_commit = lc($2); | |
2008 | + my $id = '01234567890ab'; | |
2009 | + my $desc = 'commit description'; | |
2010 | + ($id, $desc) = git_commit_info($orig_commit, $id, $desc); | |
2011 | + ERROR("GIT_COMMIT_ID", | |
2012 | + "Please use 12 to 16 chars for the git commit ID like: '${init_char}ommit $id (\"$desc\")'\n" . $herecurr); | |
1959 | 2013 | } |
1960 | 2014 | |
1961 | 2015 | # Check for wrappage within a valid hunk of the file |