]> git.proxmox.com Git - mirror_zfs.git/blobdiff - scripts/commitcheck.sh
Linux 5.0 compat: ASM_BUG macro
[mirror_zfs.git] / scripts / commitcheck.sh
index 723109112b60028bd71246a104e21fffaca80b1c..2954b0fd727e1f85d83192231c8c7a56a8501e64 100755 (executable)
@@ -11,13 +11,29 @@ function test_url()
         echo "\"$url\" is unreachable"
         return 1
     fi
+
+    return 0
+}
+
+# test commit body for length
+# lines containing urls are exempt for the length limit.
+function test_commit_bodylength()
+{
+    length="72"
+    body=$(git log -n 1 --pretty=%b "$REF" | grep -Ev "http(s)*://" | grep -E -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()
 {
-    regex='^\s*'"$1"':\s+\S+\s+\<\S+\>'
-    foundline=$(git log -n 1 "$REF" | egrep -m 1 "$regex")
+    regex='^\s*'"$1"':\s[[:print:]]+\s<[[:graph:]]+>$'
+    foundline=$(git log -n 1 "$REF" | grep -E -m 1 "$regex")
     if [ -z "$foundline" ]; then
         echo "error: missing \"$1\""
         return 1
@@ -27,18 +43,23 @@ 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(\S+)'
+    regex='^\s*'"$1"':\s\K([[:graph:]]+)$'
     foundline=$(git log -n 1 "$REF" | grep -Po "$regex")
     if [ -z "$foundline" ]; then
         echo "error: missing \"$1\""
         return 1
     fi
 
-    if ! test_url "$foundline"; then
-        return 1
-    fi
+    OLDIFS=$IFS
+    IFS=$'\n'
+    for url in $(echo -e "$foundline"); do
+        if ! test_url "$url"; then
+            return 1
+        fi
+    done
+    IFS=$OLDIFS
 
     return 0
 }
@@ -48,10 +69,10 @@ function new_change_commit()
 {
     error=0
 
-    # subject is not longer than 50 characters
-    long_subject=$(git log -n 1 --pretty=%s "$REF" | egrep -m 1 '.{51}')
+    # subject is not longer than 72 characters
+    long_subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '.{73}')
     if [ -n "$long_subject" ]; then
-        echo "error: commit subject over 50 characters"
+        echo "error: commit subject over 72 characters"
         error=1
     fi
 
@@ -61,9 +82,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
 
@@ -73,7 +92,7 @@ function new_change_commit()
 function is_openzfs_port()
 {
     # subject starts with OpenZFS means it's an openzfs port
-    subject=$(git log -n 1 --pretty=%s "$REF" | egrep -m 1 '^OpenZFS')
+    subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '^OpenZFS')
     if [ -n "$subject" ]; then
         return 0
     fi
@@ -83,10 +102,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:]]+ - ')
+    subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '^OpenZFS [[:digit:]]+(, [[: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
 
@@ -100,11 +121,6 @@ function openzfs_port_commit()
         error=1
     fi
 
-    # need a approved by line
-    if ! check_tagged_line "Approved by" ; then
-        error=1
-    fi
-
     # need ported by line
     if ! check_tagged_line "Ported-by" ; then
         error=1
@@ -123,6 +139,55 @@ 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" | grep -E -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" |
+        grep -E -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" | grep -E '^CID'); do
+        echo "$line" | grep -E '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)' > /dev/null
+        # shellcheck disable=SC2181
+        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
@@ -136,6 +201,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