History

checkpatch: update git commit message

The git commit message can be confusing, Try to clarify the message a bit to reduce the confusion when emitted. Show the correct form using Please use git commit description style 'commit <12+ chars of sha1> ("<title line>")' and if the git commit sha1 is unique, show the right sha1 to use with the actual title

Joe Perches committed 11 years ago

Commit 0d7835f1 parent 1b36b201 file · +32 −13Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+32−13
@@ -634,6 +634,8 @@ sub git_commit_info { · 633 unmodified lines
634634 $output =~ s/^\s*//gm;
635635 my @lines = split("\n", $output);
636636
637+ return ($id, $desc) if ($#lines < 0);
638+
637639 if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) {
638640 # Maybe one day convert this block of bash into something that returns
639641 # all matching commit ids, but it's very slow...
@@ -2173,21 +2175,38 @@ sub process { · 1533 unmodified lines
21732175 "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr);
21742176 }
21752177
2176−# Check for improperly formed commit descriptions
2177− if ($in_commit_log &&
2178− $line =~ /\bcommit\s+[0-9a-f]{5,}/i &&
2179− !($line =~ /\b[Cc]ommit [0-9a-f]{12,40} \("/ ||
2180− ($line =~ /\b[Cc]ommit [0-9a-f]{12,40}\s*$/ &&
2181− defined $rawlines[$linenr] &&
2182− $rawlines[$linenr] =~ /^\s*\("/))) {
2183− $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i;
2178+# Check for git id commit length and improperly formed commit descriptions
2179+ if ($in_commit_log && $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i) {
21842180 my $init_char = $1;
21852181 my $orig_commit = lc($2);
2186− my $id = '01234567890ab';
2187− my $desc = 'commit description';
2188− ($id, $desc) = git_commit_info($orig_commit, $id, $desc);
2189− ERROR("GIT_COMMIT_ID",
2190− "Please use 12 or more chars for the git commit ID like: '${init_char}ommit $id (\"$desc\")'\n" . $herecurr);
2182+ my $short = 1;
2183+ my $long = 0;
2184+ my $case = 1;
2185+ my $space = 1;
2186+ my $hasdesc = 0;
2187+ my $id = '0123456789ab';
2188+ my $orig_desc = "commit description";
2189+ my $description = "";
2190+
2191+ $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
2192+ $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
2193+ $space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
2194+ $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
2195+ if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
2196+ $orig_desc = $1;
2197+ } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
2198+ defined $rawlines[$linenr] &&
2199+ $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
2200+ $orig_desc = $1;
2201+ }
2202+
2203+ ($id, $description) = git_commit_info($orig_commit,
2204+ $id, $orig_desc);
2205+
2206+ if ($short || $long || $space || $case || ($orig_desc ne $description)) {
2207+ ERROR("GIT_COMMIT_ID",
2208+ "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
2209+ }
21912210 }
21922211
21932212 # Check for added, moved or deleted files