diff options
author | Giuseppe Di Natale <[email protected]> | 2017-10-26 10:17:00 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-10-26 10:17:00 -0700 |
commit | 8dcaf243d77b21c49092a4ffd3a641ac3407217c (patch) | |
tree | 3581f622b31691b5dc7336a8bae174c677c916ca /scripts/commitcheck.sh | |
parent | 64b8c58e3e49dcca107c2f53dd5cc7208ee6f405 (diff) |
Add Coverity defect fix commit checker support
Enable commitcheck.sh to test if a commit message is
in the expected format for a coverity defect fix.
Reviewed-by: George Melikov <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Giuseppe Di Natale <[email protected]>
Closes #6777
Diffstat (limited to 'scripts/commitcheck.sh')
-rwxr-xr-x | scripts/commitcheck.sh | 80 |
1 files changed, 75 insertions, 5 deletions
diff --git a/scripts/commitcheck.sh b/scripts/commitcheck.sh index 5bef3375d..1f78dc8a8 100755 --- a/scripts/commitcheck.sh +++ b/scripts/commitcheck.sh @@ -15,6 +15,19 @@ function test_url() return 0 } +# test commit body for length +function test_commit_bodylength() +{ + length="72" + body=$(git log -n 1 --pretty=%b "$REF" | egrep -m 1 ".{$((length + 1))}") + if [ -n "$body" ]; then + echo "error: commit message body contains line over ${length} characters" + return 1 + fi + + return 0 +} + # check for a tagged line function check_tagged_line() { @@ -29,7 +42,7 @@ function check_tagged_line() } # check for a tagged line and check that the link is valid -function check_tagged_line_with_url () +function check_tagged_line_with_url() { regex='^\s*'"$1"':\s\K([[:graph:]]+)$' foundline=$(git log -n 1 "$REF" | grep -Po "$regex") @@ -63,9 +76,7 @@ function new_change_commit() fi # ensure that no lines in the body of the commit are over 72 characters - body=$(git log -n 1 --pretty=%b "$REF" | egrep -m 1 '.{73}') - if [ -n "$body" ]; then - echo "error: commit message body contains line over 72 characters" + if ! test_commit_bodylength ; then error=1 fi @@ -85,10 +96,12 @@ function is_openzfs_port() function openzfs_port_commit() { + error=0 + # subject starts with OpenZFS dddd subject=$(git log -n 1 --pretty=%s "$REF" | egrep -m 1 '^OpenZFS [[:digit:]]+ - ') if [ -z "$subject" ]; then - echo "OpenZFS patch ports must have a summary that starts with \"OpenZFS dddd - \"" + echo "error: OpenZFS patch ports must have a subject line that starts with \"OpenZFS dddd - \"" error=1 fi @@ -125,6 +138,54 @@ function openzfs_port_commit() return $error } +function is_coverity_fix() +{ + # subject starts with Fix coverity defects means it's a coverity fix + subject=$(git log -n 1 --pretty=%s "$REF" | egrep -m 1 '^Fix coverity defects') + if [ -n "$subject" ]; then + return 0 + fi + + return 1 +} + +function coverity_fix_commit() +{ + error=0 + + # subject starts with Fix coverity defects: CID dddd, dddd... + subject=$(git log -n 1 --pretty=%s "$REF" | + egrep -m 1 'Fix coverity defects: CID [[:digit:]]+(, [[:digit:]]+)*') + if [ -z "$subject" ]; then + echo "error: Coverity defect fixes must have a subject line that starts with \"Fix coverity defects: CID dddd\"" + error=1 + fi + + # need a signed off by + if ! check_tagged_line "Signed-off-by" ; then + error=1 + fi + + # test each summary line for the proper format + OLDIFS=$IFS + IFS=$'\n' + for line in $(git log -n 1 --pretty=%b "$REF" | egrep '^CID'); do + echo "$line" | egrep '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)' > /dev/null + if [[ $? -ne 0 ]]; then + echo "error: commit message has an improperly formatted CID defect line" + error=1 + fi + done + IFS=$OLDIFS + + # ensure that no lines in the body of the commit are over 72 characters + if ! test_commit_bodylength; then + error=1 + fi + + return $error +} + if [ -n "$1" ]; then REF="$1" fi @@ -138,6 +199,15 @@ if is_openzfs_port; then fi fi +# if coverity fix, test against that +if is_coverity_fix; then + if ! coverity_fix_commit; then + exit 1 + else + exit 0 + fi +fi + # have a normal commit if ! new_change_commit ; then exit 1 |