Whamcloud - gitweb
LU-2053 crypto: Fix cfs_crypto_hash memleak
[fs/lustre-release.git] / build / commit-msg
index 331db3d..422117e 100755 (executable)
@@ -19,21 +19,22 @@ init() {
         readonly SAVE="$(basename $ORIGINAL).$(date +%Y%m%d.%H%M%S)"
         readonly SIGNOFF="Signed-off-by:"
         readonly CHANGEID="Change-Id:"
+        readonly TESTPARAMS="Test-Parameters:"
         readonly INNOCUOUS=$(echo \
                         Acked-by \
                         Tested-by \
-                        CC \
                         Reported-by \
                         Reviewed-by \
+                        CC \
                 | tr ' ' '|')
-        readonly WIDTH_SUM=64
+        readonly WIDTH_SUM=62
         readonly WIDTH_REG=70
         readonly JIRA_FMT_A="^[A-Z]\{2,5\}-[0-9]\{1,5\} [-a-z0-9]\{2,9\}: "
         readonly JIRA_FMT_B="^[A-Z]\{2,5\}-[0-9]\{1,5\} "
 
         # Identify a name followed by an email address.
         #
-        readonly EMAILPAT=$'[ \t]*[a-zA-Z][^<>]*[ \t]<[^@ \t>]+@[^@ \t>]+>'
+        readonly EMAILPAT=$'[ \t]*[^<> ]* [^<>]* <[^@ \t>]+@[a-zA-Z0-9.-]+\.[a-z]+>'
 
         HAS_ERROR=false
         HAS_SUMMARY=false
@@ -41,7 +42,6 @@ init() {
         HAS_BODY=false
         HAS_SIGNOFF=false
         HAS_CHANGEID=false
-        HAS_DIFF=false
 
         IS_WRAPPING_UP=false
 
@@ -77,7 +77,7 @@ function do_signoff() {
         ck_wrapup
         # Signed-off-by: First Last <email@host.domain>
         local txt=$(echo "${LINE#*: }" | grep -E "${EMAILPAT}")
-        if (( ${#txt} == 0 )) ; then
+        if (( ${#txt} == 0 )); then
                 error "$SIGNOFF line requires name and email address"
         else
                 HAS_SIGNOFF=true # require at least one
@@ -92,7 +92,7 @@ function do_changeid() {
         # capital "I" plus 40 hex digits
         #
         local txt=$(echo "$LINE" | grep "^$CHANGEID I[0-9a-fA-F]\{40\}\$")
-        (( ${#txt} > 0 )) || \
+        (( ${#txt} > 0 )) ||
                 error "has invalid $CHANGEID line for Gerrit tracking"
 
         HAS_CHANGEID=true
@@ -111,23 +111,23 @@ function do_default_line() {
                 error "invalid signoff section line"
                 return
         }
-        if (( NUM == 1 )) ; then
+        if (( NUM == 1 )); then
                 HAS_JIRA_COMPONENT=$(echo "$LINE" | grep "$JIRA_FMT_A")
 
-                if (( ${#HAS_JIRA_COMPONENT} == 0 )) ; then
+                if (( ${#HAS_JIRA_COMPONENT} == 0 )); then
                         HAS_JIRA=$(echo "$LINE" | grep "$JIRA_FMT_B")
-                        if (( ${#HAS_JIRA} > 0 )) ; then
+                        if (( ${#HAS_JIRA} > 0 )); then
                                 error "has no component in summary."
                         else
                                 error "missing JIRA ticket number."
                         fi
-                elif (( ${#LINE} > WIDTH_SUM )) ; then
+                elif (( ${#LINE} > WIDTH_SUM )); then
                         error "summary longer than $WIDTH_SUM columns."
                 else
                         HAS_SUMMARY=true
                 fi
 
-        elif (( ${#LINE} > WIDTH_REG )) ; then
+        elif (( ${#LINE} > WIDTH_REG )); then
                 error "has line longer than $WIDTH_REG columns."
         elif ! $HAS_BODY && ! $HAS_LAST_BLANK; then
                 error "has no blank line after summary."
@@ -135,7 +135,6 @@ function do_default_line() {
                 HAS_BODY=true
         fi
         HAS_LAST_BLANK=false
-        HAS_DIFF=false
 }
 
 # Add a new unique Change-Id
@@ -148,7 +147,7 @@ new_changeid() {
                         git rev-parse HEAD 2>/dev/null
                         grep -v "^$SIGNOFF" "$ORIGINAL" | git stripspace -s
                 } | git hash-object --stdin)
-        (( ${#NEWID} > 0 )) || \
+        (( ${#NEWID} > 0 )) ||
                 die "git hash-object failed for $CHANGEID:"
 
         echo "$CHANGEID I$NEWID"
@@ -159,7 +158,7 @@ new_changeid() {
 #
 error() {
         (( ${#LINE} > 0 )) && echo "line $NUM: $LINE"
-        echo "error: commit message $*" | fmt --split-only
+        echo "error: commit message $*" | fmt
         HAS_ERROR=true
 } 1>&2
 
@@ -193,14 +192,18 @@ usage() {
        $SIGNOFF Your Real Name <your_email@domain.name>
        $CHANGEID Ixxxx(added automatically if missing)xxxx
 
-       Included in the "sign off section" may be any of several other
-       tag lines:
-           $(echo "$INNOCUOUS" | tr '|' ' ')
        The "$CHANGEID" line should only be there when updating a previous
-       commit/submission.  Copy the one from that commit.
+       commit/submission.  Copy the one from the original commit.
+
+       The "sign off section" may also include several other tag lines:
+       $(for T in $(tr '|' ' ' <<< "$INNOCUOUS"); do       \
+            echo "    $T: Some Person <email@domain.com>"; \
+         done)
+       $TESTPARAMS optional additional test parameters
+       {Organization}-bug-id: associated external change identifier
        EOF
 
-        mv "$ORIGINAL" "$SAVE" && \
+        mv "$ORIGINAL" "$SAVE" &&
                 echo "$0: saved original commit comment to $SAVE" 1>&2
 }
 
@@ -212,11 +215,11 @@ while IFS= read -u3 LINE; do
         case "$LINE" in
         $SIGNOFF* )   do_signoff   ;;
         $CHANGEID* )  do_changeid  ;;
+        $TESTPARAMS* ) ck_wrapup   ;;
 
         "")
-                $IS_WRAPPING_UP && \
-                        error "blank lines not allowed in signoff section"
                 HAS_LAST_BLANK=true
+                $IS_WRAPPING_UP && continue
                 ;;
 
         \#*)
@@ -228,21 +231,31 @@ while IFS= read -u3 LINE; do
                 # there are diff and index lines, skip the rest of the input:
                 #   diff --git a/build/commit-msg b/build/commit-msg
                 #   index 80a3442..acb4c50 100755
-                # If a "diff --git" line is not followed by an index line,
-                # do the default line processing on both lines.
+                #   deleted file mode 100644
+                #   old mode 100644
+                # If a "diff --git" line is not followed by one of these
+                # lines, do the default line processing on both lines.
                 #
                 IFS= read -u3 INDEX || break
                 ((NUM += 1))
-                ln=$(echo "$INDEX" | grep "^index [0-9a-fA-F]\{6,\}\.\.")
-                (( ${#ln} > 1 )) && break
+                case "$INDEX" in
+                "index "[0-9a-fA-F]*) break ;;
+                "deleted file mode "*) break  ;;
+                "old mode "*) break ;;
+                esac
                 LINE=${LINE}$'\n'${INDEX}
                 do_default_line
                 ;;
 
         *)
-                if [[ "$LINE" =~ ^($INNOCUOUS): ]] ; then
+                if [[ "$LINE" =~ ^($INNOCUOUS): ]]; then
                         do_innocuous
+                elif [[ "$LINE" =~ ^[A-Za-z0-9_-]+-bug-id: ]]; then
+                        ck_wrapup
                 else
+                        # Allow arbitrary external bug identifiers for tracking.
+                        # I can't seem to find a pattern for the "case" that
+                        # checks for "*-bug-id", so this is checked here.
                         do_default_line
                 fi
                 ;;