[PATCH] scripts, checkpatch.pl, provide a better output message for commit id format [v2]

From: Prarit Bhargava
Date: Mon Oct 20 2014 - 18:49:50 EST


I tested this using both lower and upper case 'c' with the following commit
text:

Derp, derpy derp. Derps derpy derpy derp derp derp derp.
Some other text besides derp.
Stuff.

11 chars, SHOULD FAIL
commit 1234567890a

12 chars
commit 1234567890ab

13 chars
commit 1234567890abc

14 chars
commit 1234567890abcd

commit 1234567890f
("11 chars, separated into two lines SHOULD FAIL")

commit 1234567890af
("12 chars, separated into two lines")

commit 1234567890abf
("13 chars, separated into two lines")

commit 1234567890abcf
("14 chars, separated into two lines")

commit 1234567890f ("11 chars, one line SHOULD FAIL")

commit 1234567890af ("12 chars, one line")

commit 1234567890abf ("13 chars, one line")

commit 1234567890abcf ("14 chars, one line")

The output, as expected is 6 errors:

ERROR: Please use 12 or more chars for the git commit ID
commit 1234567890a

ERROR: Please use 12 or more chars for the git commit ID
commit 1234567890f

ERROR: Please format the git commit ID like: 'commit 01234567890ab ("commit description")'
commit 1234567890af

ERROR: Please format the git commit ID like: 'commit 01234567890ab ("commit description")'
commit 1234567890abf

ERROR: Please format the git commit ID like: 'commit 01234567890ab ("commit description")'
commit 1234567890abcf

ERROR: Please use 12 or more chars for the git commit ID
commit 1234567890f ("11 chars, one line SHOULD FAIL")

P.
----8<----

I put together a patch with an incorrect format and the following error
was returned by checkpatch.pl:

ERROR: Please use 12 or more chars for the git commit ID like: 'Commit
09ec54429c6d ("clocksource: Move cycle_last validation to core code")'
Commit 09ec54429c6d10f87d1f084de53ae2c1c3a81108, clocksource: Move

As can be seen by the output the commit ID length is accurate, and it is the
formatting that is generating an error. The message is confusing and should
be separated into two warnings, one for the git commit ID length, and the other
for the format.

Cc: Andy Whitcroft <apw@xxxxxxxxxxxxx>
Cc: Joe Perches <joe@xxxxxxxxxxx>
Signed-off-by: Prarit Bhargava <prarit@xxxxxxxxxx>

[v2]: Add separate messages for warnings instead of one global format
warning.
---
scripts/checkpatch.pl | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 374abf4..f81d7a8 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2160,21 +2160,25 @@ sub process {
"Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr);
}

-# Check for improperly formed commit descriptions
+# Check for git id commit length and improperly formed commit descriptions
if ($in_commit_log &&
- $line =~ /\bcommit\s+[0-9a-f]{5,}/i &&
- !($line =~ /\b[Cc]ommit [0-9a-f]{12,40} \("/ ||
- ($line =~ /\b[Cc]ommit [0-9a-f]{12,40}\s*$/ &&
- defined $rawlines[$linenr] &&
- $rawlines[$linenr] =~ /^\s*\("/))) {
- $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i;
+ $line =~ /\b[Cc]ommit\s+[0-9a-f]{5,}/i &&
+ !($line =~ /\b[Cc]ommit [0-9a-f]{12,40}/ )) {
+ ERROR("GIT_COMMIT_ID_12_CHARS",
+ "Please use 12 or more chars for the git commit ID\n" . $herecurr);
+ } elsif ($in_commit_log &&
+ $line =~ /\b[Cc]ommit [0-9a-f]{12,40}\s*$/ &&
+ defined $rawlines[$linenr] &&
+ $rawlines[$linenr] =~ /^\s*\("/) {
+ $line =~ /\b(c)ommit\s+([0-9a-f]{12,40})/i;
my $init_char = $1;
my $orig_commit = lc($2);
my $id = '01234567890ab';
my $desc = 'commit description';
- ($id, $desc) = git_commit_info($orig_commit, $id, $desc);
- ERROR("GIT_COMMIT_ID",
- "Please use 12 or more chars for the git commit ID like: '${init_char}ommit $id (\"$desc\")'\n" . $herecurr);
+ ($id, $desc) = git_commit_info($orig_commit,
+ $id, $desc);
+ ERROR("GIT_COMMIT_ID_DESCRIPTION",
+ "Please format the git commit ID like: '${init_char}ommit $id (\"$desc\")'\n" . $herecurr);
}

# Check for added, moved or deleted files
--
1.7.9.3

--
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/