]> git.ozlabs.org Git - next-scripts/blobdiff - check_fixes
get_commit: cpture all the Signed-off-bys as Ccs
[next-scripts] / check_fixes
index 17cfdf0c327135aeb926e7b61f9656a264d2466d..d75e1efc7f8b49e94577ac47f0170a8ca5f825fd 100755 (executable)
@@ -10,11 +10,14 @@ if [ -z "$commits" ]; then
         exit 0
 fi
 
+# This should be a git tree that contains *only* Linus' tree
 Linus_tree="${HOME}/kernels/linus.git"
-done_file="${HOME}/tmp/check_fixes_done"
-split_re='^([[:xdigit:]]+)[[: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:]]*$ ]]
@@ -22,20 +25,20 @@ strip_spaces()
 }
 
 for c in $commits; do
-       if [ -r "$done_file" ] && grep -q -Fx "$c" "$done_file"; then
-               continue
-       fi
 
+       commit_log=$(git log -1 --format='%h ("%s")' "$c")
        commit_msg="In commit
 
-  $(git log -1 --format='%h ("%s")' $c)
+  $commit_log
 
 "
+
        fixes_lines=$(git log -1 --format='%B' "$c" |
                        grep -i '^[[:space:]]*Fixes:')
 
-       while read fline; do
-               f=$(echo "$fline" | sed 's/^[[:space:]]*Fixes:[[:space:]]*//i')
+       while read -r fline; do
+               [[ "$fline" =~ ^[[:space:]]*[Ff][Ii][Xx][Ee][Ss]:[[:space:]]*(.*)$ ]]
+               f="${BASH_REMATCH[1]}"
                fixes_msg="Fixes tag
 
   $fline
@@ -46,11 +49,20 @@ has these problem(s):
                sha=
                subject=
                msg=
-               [[ "$f" =~ $split_re ]]
-               sha="${BASH_REMATCH[1]}"
-               subject="${BASH_REMATCH[2]}"
-
-               if [ -z "$sha" ]; then
+               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
+                       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
@@ -62,7 +74,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
@@ -73,10 +85,19 @@ has these problem(s):
                fi
 
                # strip matching quotes at the start and end of the subject
-               re='^(['\''"])(.*)\1$'
-               if [[ "$subject" =~ $re ]]; then
-                       subject="${BASH_REMATCH[2]}"
-               elif [[ "$subject" =~ ^[\'\"](.*)$ ]]; then
+               # the unicode characters in the classes are
+               # U+201C LEFT DOUBLE QUOTATION MARK
+               # U+201D RIGHT DOUBLE QUOTATION MARK
+               # U+2018 LEFT SINGLE QUOTATION MARK
+               # U+2019 RIGHT SINGLE QUOTATION MARK
+               re1=$'^[\"\u201C](.*)[\"\u201D]$'
+               re2=$'^[\'\u2018](.*)[\'\u2019]$'
+               re3=$'^[\"\'\u201C\u2018](.*)$'
+               if [[ "$subject" =~ $re1 ]]; then
+                       subject="${BASH_REMATCH[1]}"
+               elif [[ "$subject" =~ $re2 ]]; then
+                       subject="${BASH_REMATCH[1]}"
+               elif [[ "$subject" =~ $re3 ]]; then
                        subject="${BASH_REMATCH[1]}"
                        msg="${msg:+${msg}${nl}}  - Subject has leading but no trailing quotes"
                fi
@@ -107,9 +128,9 @@ 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")
+               lsha=$(cd "$Linus_tree" && git rev-parse -q --verify "$sha")
                if [ -z "$lsha" ]; then
                        count=$(git rev-list --count "$sha".."$c")
                        if [ "$count" -eq 0 ]; then