From: Andreas Dilger Date: Wed, 19 Oct 2011 20:05:33 +0000 (-0600) Subject: LU-553 build: fix commit-msg line width check X-Git-Tag: 2.1.52~38 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=2c5130ef6bb0e86ffa82e64398794aa0f3330694 LU-553 build: fix commit-msg line width check 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 Signed-off-by: Andreas Dilger Change-Id: I0bcfdedbe6d33fd5f81381ca33862a10d6b41b38 Reviewed-on: http://review.whamcloud.com/1553 Reviewed-by: Bobi Jam Tested-by: Bobi Jam Reviewed-by: Oleg Drokin --- diff --git a/build/commit-msg b/build/commit-msg index 80a3442..6bd9a10 100755 --- a/build/commit-msg +++ b/build/commit-msg @@ -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 $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 + 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