]> git.ozlabs.org Git - next-scripts/blobdiff - check_fixes
update to_build_host a bit
[next-scripts] / check_fixes
index 29a204dbded83fc7098286dcd2e4240384f40096..84d72150734715e44c73da727f1f07d0d6658625 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+shopt -s extglob
+
 if [ "$#" -lt 1 ]; then
         printf 'Usage: %s <commit range>\n', "$0" 1>&2
         exit 1
@@ -12,59 +14,49 @@ fi
 
 # This should be a git tree that contains *only* Linus' tree
 Linus_tree="${HOME}/kernels/linus.git"
-split_re1='^([[:xdigit:]]{5,})[[:space:]]+(.*)$'
-split_re2='^([[:xdigit:]]{5,})[[:space:]]*(.*)$'
-split_re3='^([Cc][Oo][Mm][Mm][Ii][Tt])[[:space:]]*([[:xdigit:]]{5,})[[:space:]]*(.*)$'
+
+split_re='^([Cc][Oo][Mm][Mm][Ii][Tt])?[[:space:]]*([[:xdigit:]]{5,})([[:space:]]*)(.*)$'
 nl=$'\n'
+tab=$'\t'
 
 # Strip the leading and training spaces from a string
 strip_spaces()
 {
-       [[ "$1" =~ ^[[:space:]]*(.*[^[:space:]])[[:space:]]*$ ]]
-       echo "${BASH_REMATCH[1]}"
+       local str="${1##*([[:space:]])}"
+       str="${str%%*([[:space:]])}"
+       echo "$str"
 }
 
 for c in $commits; do
 
-       commit_log=$(git log -1 --format='%h ("%s")' "$c")
-       commit_msg="In commit
-
-  $commit_log
-
-"
-
-       fixes_lines=$(git log -1 --format='%B' "$c" |
-                       grep -i '^[[:space:]]*Fixes:')
+       printf -v commit_msg 'In commit\n\n  %s\n\n' \
+               "$(git log -1 --format='%h ("%s")' "$c")"
 
-       while read -r fline; do
-               [[ "$fline" =~ ^[[:space:]]*[Ff][Ii][Xx][Ee][Ss]:[[:space:]]*(.*)$ ]]
-               f="${BASH_REMATCH[1]}"
-               fixes_msg="Fixes tag
+       readarray -t fixes_lines < <(git log -1 --format='%B' "$c" |
+                                       grep -i '^[[:space:]]*Fixes:')
+       fixes_lines=( "${fixes_lines[@]##*([[:space:]])}" )
+       fixes_lines=( "${fixes_lines[@]%%*([[:space:]])}" )
 
-  $fline
-
-has these problem(s):
-
-"
+       for fline in "${fixes_lines[@]}"; do
+               f="${fline##[Ff][Ii][Xx][Ee][Ss]:*([[:space:]])}"
+               printf -v fixes_msg 'Fixes tag\n\n  %s\n\nhas these problem(s):\n\n' "$fline"
                sha=
                subject=
                msg=
-               [[ "$f" =~ $split_re1 ]]
-               sha="${BASH_REMATCH[1]}"
-               subject="${BASH_REMATCH[2]}"
-
-               if [ -z "$sha" ]; then
-                       [[ "$f" =~ $split_re2 ]]
-                       sha="${BASH_REMATCH[1]}"
-                       subject="${BASH_REMATCH[2]}"
-                       if [ -z "$sha" ]; then
-                               [[ "$f" =~ $split_re3 ]]
-                               sha="${BASH_REMATCH[2]}"
-                               subject="${BASH_REMATCH[3]}"
-                               msg="${msg:+${msg}${nl}}  - leading word '${BASH_REMATCH[1]}' unexpected"
+               if [[ "$f" =~ $split_re ]]; then
+                       first="${BASH_REMATCH[1]}"
+                       sha="${BASH_REMATCH[2]}"
+                       spaces="${BASH_REMATCH[3]}"
+                       subject="${BASH_REMATCH[4]}"
+                       if [ "$first" ]; then
+                               msg="${msg:+${msg}${nl}}  - leading word '$first' unexpected"
                        fi
-               fi
-               if [ -z "$sha" ]; then
+                       if [ -z "$subject" ]; then
+                               msg="${msg:+${msg}${nl}}  - missing subject"
+                       elif [ -z "$spaces" ]; then
+                               msg="${msg:+${msg}${nl}}  - missing space between the SHA1 and the subject"
+                       fi
+               else
                        printf '%s%s  - %s\n' "$commit_msg" "$fixes_msg" 'No SHA1 recognised'
                        commit_msg=''
                        continue
@@ -76,7 +68,7 @@ has these problem(s):
                fi
 
                if [ "${#sha}" -lt 12 ]; then
-                       msg="${msg:+${msg}${nl}}  - SHA1 should be at least 12 digits long"
+                       msg="${msg:+${msg}${nl}}  - SHA1 should be at least 12 digits long${nl}    Can be fixed by setting core.abbrev to 12 (or more) or (for git v2.11${nl}    or later) just making sure it is not set (or set to \"auto\")."
                fi
                # reduce the subject to the part between () if there
                if [[ "$subject" =~ ^\((.*)\) ]]; then
@@ -130,7 +122,7 @@ has these problem(s):
                target_subject=$(strip_spaces "$target_subject")
 
                if [ "$subject" != "${target_subject:0:${#subject}}" ]; then
-                       msg="${msg:+${msg}${nl}}  - Subject does not match target commit subject"
+                       msg="${msg:+${msg}${nl}}  - Subject does not match target commit subject${nl}    Just use${nl}${tab}git log -1 --format='Fixes: %h (\"%s\")'"
                fi
                lsha=$(cd "$Linus_tree" && git rev-parse -q --verify "$sha")
                if [ -z "$lsha" ]; then
@@ -143,7 +135,7 @@ has these problem(s):
                        printf '%s%s%s\n' "$commit_msg" "$fixes_msg" "$msg"
                        commit_msg=''
                fi
-       done <<< "$fixes_lines"
+       done
 done
 
 exit 0