Whamcloud - gitweb
LU-553 build: fix commit-msg line width check
authorAndreas Dilger <adilger@whamcloud.com>
Wed, 19 Oct 2011 20:05:33 +0000 (14:05 -0600)
committerOleg Drokin <green@whamcloud.com>
Thu, 27 Oct 2011 03:33:22 +0000 (23:33 -0400)
Fix the calculation of the commit message line width to skip the
trailing linefeed character.

Don't use the "git hash_object -t commit" option, since this makes
some versions of Git unhappy and generate an empty Commit-Id string.

Skip diffstat output from "commit -v" when validating commit comment.

Validate the Change-Id: line has the proper ID format.

Reported-by: Bobi Jam <bobijam@whamcloud.com>
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I0bcfdedbe6d33fd5f81381ca33862a10d6b41b38
Reviewed-on: http://review.whamcloud.com/1553
Reviewed-by: Bobi Jam <bobijam@whamcloud.com>
Tested-by: Bobi Jam <bobijam@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
build/commit-msg

index 80a3442..6bd9a10 100755 (executable)
@@ -16,6 +16,8 @@ ORIGINAL="$1"
 REVISED="$(mktemp "$1.XXXXXX")"
 SIGNOFF="Signed-off-by:"
 CHANGEID="Change-Id:"
+WIDTH_SUM=64
+WIDTH_REG=70
 
 # Check for, and add if missing, a unique Change-Id
 new_changeid() {
@@ -25,7 +27,7 @@ new_changeid() {
                git write-tree
                git rev-parse HEAD 2>/dev/null
                grep -v "$SIGNOFF" "$ORIGINAL" | git stripspace -s
-       } | git hash-object -t commit --stdin
+       } | git hash-object --stdin
 }
 
 usage() {
@@ -41,7 +43,7 @@ usage() {
 
        A more detailed explanation.  This can be as detailed as you'd like.
        Please explain both what problem was solved and a good high-level
-       description of how it was solved.  Wrap lines at 70 columns or less.
+       description of how it was solved.  Wrap at $WIDTH_REG columns or less.
 
        $SIGNOFF Your Real Name <your_email@domain.name>
        $CHANGEID Ixxxx(added automatically if missing)xxxx
@@ -54,6 +56,7 @@ export HAS_SIGNOFF=false
 export HAS_SUMMARY=false
 export HAS_BLANK=false
 export HAS_COMMENTS=false
+export HAS_DIFF=false
 
 grep -q "^$CHANGEID" "$ORIGINAL" && HAS_CHANGEID=true || HAS_CHANGEID=false
 
@@ -62,13 +65,14 @@ export NUM=1
 
 IFS=""
 while read LINE; do
-       LENGTH=$(echo $LINE | wc -c)
+       WIDTH=$(($(echo $LINE | wc -c) - 1)) # -1 for end-of-line character
 
        case "$LINE" in
        $SIGNOFF*)
                $HAS_SUMMARY || usage "missing summary before $SIGNOFF."
                $HAS_BLANK || usage "missing blank line before $SIGNOFF."
-               GOOD=$(echo "$LINE" | grep "^$SIGNOFF .* .* <.*@.*>")
+               # Signed-off-by: First Last <email@host.domain>
+               GOOD=$(echo "$LINE" | grep "^$SIGNOFF .* .* <.*@[^.]*\..*>")
                [ -z "$GOOD" ] &&
                        usage "missing valid commit summary line to show" \
                              "agreement with code submission requirements at"
@@ -79,20 +83,32 @@ while read LINE; do
        $CHANGEID*)
                $HAS_SUMMARY || usage "missing summary before $CHANGEID line."
                $HAS_BLANK || usage "missing blank line before $CHANGEID line."
+               # Change-Id: I762ab50568f25527176ae54e92c446cf06112097
+               GOOD=$(echo "$LINE" | grep "^$CHANGEID I[0-9a-fA-F]\{40\}")
+               [ -z "$GOOD" ] &&
+                       usage "missing valid $CHANGEID line for Gerrit tracking"
                HAS_CHANGEID=true
                echo $LINE
                ;;
        "")     [ $HAS_SUMMARY -a $NUM -eq 2 ] && HAS_BLANK=true
                echo $LINE
                ;;
+       diff*|index*) # beginning of uncommented diffstat from "commit -v"
+               # diff --git a/build/commit-msg b/build/commit-msg
+               # index 80a3442..acb4c50 100755
+               DIFF=$(echo "$LINE" | grep -- "^diff --git a/")
+               [ "$DIFF" ] && HAS_DIFF=true && continue
+               INDEX=$(echo "$LINE" | grep -- "^index [0-9a-fA-F]\{6,\}\.\.")
+               [ $HAS_DIFF -a "$INDEX" ] && break || HAS_DIFF=false
+               ;;
        \#*)    HAS_COMMENTS=true
                continue
                ;;
        *)      if [ $NUM -eq 1 ]; then
                        FMT="^[A-Z]\{2,5\}-[0-9]\{1,5\} [-a-z0-9]\{2,9\}: "
                        GOOD=$(echo "$LINE" | grep "$FMT")
-                       [ $LENGTH -gt 64 ] &&
-                               usage "summary longer than 64 columns."
+                       [ $WIDTH -gt $WIDTH_SUM ] &&
+                               usage "summary longer than $WIDTH_SUM columns."
                        if [ -z "$GOOD" ]; then
                                FMT="^[A-Z]\{2,5\}-[0-9]\{1,5\} "
                                NO_SUBSYS=$(echo "$LINE" | grep "$FMT")
@@ -101,9 +117,10 @@ while read LINE; do
                                usage "missing valid commit summary line."
                        fi
                        HAS_SUMMARY=true
-               elif [ $LENGTH -gt 70 ]; then
-                       usage "has lines longer than 70 columns."
+               elif [ $WIDTH -gt $WIDTH_REG ]; then
+                       usage "has lines longer than $WIDTH_REG columns."
                fi
+               HAS_DIFF=false
                echo $LINE
                ;;
        esac