@@ -1181,7 +1181,8 @@ sub git_commit_info {
11811181# git log --format='%H %s' -1 $line |
11821182# echo "commit $(cut -c 1-12,41-)"
11831183# done
1184- } elsif ($lines [0] =~ / ^fatal: ambiguous argument '$commit ': unknown revision or path not in the working tree\. / ) {
1184+ } elsif ($lines [0] =~ / ^fatal: ambiguous argument '$commit ': unknown revision or path not in the working tree\. / ||
1185+ $lines [0] =~ / ^fatal: bad object $commit / ) {
11851186 $id = undef ;
11861187 } else {
11871188 $id = substr ($lines [0], 0, 12);
@@ -2587,6 +2588,8 @@ sub process {
25872588 my $reported_maintainer_file = 0;
25882589 my $non_utf8_charset = 0;
25892590
2591+ my $last_git_commit_id_linenr = -1;
2592+
25902593 my $last_blank_line = 0;
25912594 my $last_coalesced_string_linenr = -1;
25922595
@@ -3170,10 +3173,20 @@ sub process {
31703173 }
31713174
31723175# Check for git id commit length and improperly formed commit descriptions
3173- if ($in_commit_log && !$commit_log_possible_stack_dump &&
3176+ # A correctly formed commit description is:
3177+ # commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
3178+ # with the commit subject '("' prefix and '")' suffix
3179+ # This is a fairly compilicated block as it tests for what appears to be
3180+ # bare SHA-1 hash with minimum length of 5. It also avoids several types of
3181+ # possible SHA-1 matches.
3182+ # A commit match can span multiple lines so this block attempts to find a
3183+ # complete typical commit on a maximum of 3 lines
3184+ if ($perl_version_ok &&
3185+ $in_commit_log && !$commit_log_possible_stack_dump &&
31743186 $line !~ / ^\s *(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
31753187 $line !~ / ^This reverts commit [0-9a-f]{7,40}/ &&
3176- ($line =~ / \b commit\s +[0-9a-f]{5,}\b /i ||
3188+ (($line =~ / \b commit\s +[0-9a-f]{5,}\b /i ||
3189+ ($line =~ / \b commit\s *$ /i && defined ($rawlines [$linenr ]) && $rawlines [$linenr ] =~ / ^\s *[0-9a-f]{5,}\b /i )) ||
31773190 ($line =~ / (?:\s |^)[0-9a-f]{12,40}(?:[\s "'\(\[ ]|$) /i &&
31783191 $line !~ / [\<\[ ][0-9a-f]{12,40}[\>\] ]/i &&
31793192 $line !~ / \b fixes:\s *[0-9a-f]{12,40}/i ))) {
@@ -3183,49 +3196,56 @@ sub process {
31833196 my $long = 0;
31843197 my $case = 1;
31853198 my $space = 1;
3186- my $hasdesc = 0;
3187- my $hasparens = 0;
31883199 my $id = ' 0123456789ab' ;
31893200 my $orig_desc = " commit description" ;
31903201 my $description = " " ;
3202+ my $herectx = $herecurr ;
3203+ my $has_parens = 0;
3204+ my $has_quotes = 0;
3205+
3206+ my $input = $line ;
3207+ if ($line =~ / (?:\b commit\s +[0-9a-f]{5,}|\b commit\s *$) /i ) {
3208+ for (my $n = 0; $n < 2; $n ++) {
3209+ if ($input =~ / \b commit\s +[0-9a-f]{5,}\s *($balanced_parens )/i ) {
3210+ $orig_desc = $1 ;
3211+ $has_parens = 1;
3212+ # Always strip leading/trailing parens then double quotes if existing
3213+ $orig_desc = substr ($orig_desc , 1, -1);
3214+ if ($orig_desc =~ / ^".*"$ / ) {
3215+ $orig_desc = substr ($orig_desc , 1, -1);
3216+ $has_quotes = 1;
3217+ }
3218+ last ;
3219+ }
3220+ last if ($#lines < $linenr + $n );
3221+ $input .= " " . trim($rawlines [$linenr + $n ]);
3222+ $herectx .= " $rawlines [$linenr + $n ]\n " ;
3223+ }
3224+ $herectx = $herecurr if (!$has_parens );
3225+ }
31913226
3192- if ($line =~ / \b (c)ommit\s +([0-9a-f]{5,})\b /i ) {
3227+ if ($input =~ / \b (c)ommit\s +([0-9a-f]{5,})\b /i ) {
31933228 $init_char = $1 ;
31943229 $orig_commit = lc ($2 );
3195- } elsif ($line =~ / \b ([0-9a-f]{12,40})\b /i ) {
3230+ $short = 0 if ($input =~ / \b commit\s +[0-9a-f]{12,40}/i );
3231+ $long = 1 if ($input =~ / \b commit\s +[0-9a-f]{41,}/i );
3232+ $space = 0 if ($input =~ / \b commit [0-9a-f]/i );
3233+ $case = 0 if ($input =~ / \b [Cc]ommit\s +[0-9a-f]{5,40}[^A-F]/ );
3234+ } elsif ($input =~ / \b ([0-9a-f]{12,40})\b /i ) {
31963235 $orig_commit = lc ($1 );
31973236 }
31983237
3199- $short = 0 if ($line =~ / \b commit\s +[0-9a-f]{12,40}/i );
3200- $long = 1 if ($line =~ / \b commit\s +[0-9a-f]{41,}/i );
3201- $space = 0 if ($line =~ / \b commit [0-9a-f]/i );
3202- $case = 0 if ($line =~ / \b [Cc]ommit\s +[0-9a-f]{5,40}[^A-F]/ );
3203- if ($line =~ / \b commit\s +[0-9a-f]{5,}\s +\( "([^"]+)"\) /i ) {
3204- $orig_desc = $1 ;
3205- $hasparens = 1;
3206- } elsif ($line =~ / \b commit\s +[0-9a-f]{5,}\s *$ /i &&
3207- defined $rawlines [$linenr ] &&
3208- $rawlines [$linenr ] =~ / ^\s *\( "([^"]+)"\) / ) {
3209- $orig_desc = $1 ;
3210- $hasparens = 1;
3211- } elsif ($line =~ / \b commit\s +[0-9a-f]{5,}\s +\( "[^"]+$ /i &&
3212- defined $rawlines [$linenr ] &&
3213- $rawlines [$linenr ] =~ / ^\s *[^"]+"\) / ) {
3214- $line =~ / \b commit\s +[0-9a-f]{5,}\s +\( "([^"]+)$ /i ;
3215- $orig_desc = $1 ;
3216- $rawlines [$linenr ] =~ / ^\s *([^"]+)"\) / ;
3217- $orig_desc .= " " . $1 ;
3218- $hasparens = 1;
3219- }
3220-
32213238 ($id , $description ) = git_commit_info($orig_commit ,
32223239 $id , $orig_desc );
32233240
32243241 if (defined ($id ) &&
3225- ($short || $long || $space || $case || ($orig_desc ne $description ) || !$hasparens )) {
3242+ ($short || $long || $space || $case || ($orig_desc ne $description ) || !$has_quotes ) &&
3243+ $last_git_commit_id_linenr != $linenr - 1) {
32263244 ERROR(" GIT_COMMIT_ID" ,
3227- " Please use git commit description style 'commit <12+ chars of sha1> (\" <title line>\" )' - ie: '${init_char} ommit $id (\" $description \" )'\n " . $herecurr );
3245+ " Please use git commit description style 'commit <12+ chars of sha1> (\" <title line>\" )' - ie: '${init_char} ommit $id (\" $description \" )'\n " . $herectx );
32283246 }
3247+ # don't report the next line if this line ends in commit and the sha1 hash is the next line
3248+ $last_git_commit_id_linenr = $linenr if ($line =~ / \b commit\s *$ /i );
32293249 }
32303250
32313251# Check for added, moved or deleted files
0 commit comments