From: Stephen Rothwell Date: Fri, 18 Jan 2019 02:40:03 +0000 (+1100) Subject: add check_fixes script X-Git-Url: http://git.ozlabs.org/?p=next-scripts;a=commitdiff_plain;h=1e4ca00a37b80f79a47de3a4f2d3215fe767ff1b add check_fixes script and associated bad_fixes mail helper --- diff --git a/bad_fixes b/bad_fixes new file mode 100755 index 0000000..7b3e263 --- /dev/null +++ b/bad_fixes @@ -0,0 +1,11 @@ +#!/bin/bash + +subject="Fixes tag needs some work in the BRANCH tree" + +tools_dir=$(dirname "$0") +"$tools_dir"/message_helper "$@" "$subject" <\n', "$0" 1>&2 + exit 1 +fi + +commits=$(git rev-list --no-merges -i --grep='^[[:space:]]*Fixes:' "$@") +if [ -z "$commits" ]; then + exit 0 +fi + +Linus_tree="${HOME}/kernels/linus.git" +done_file="${HOME}/tmp/check_fixes_done" +split_re='^([[:xdigit:]]+)[[:space:]]+(.*)$' +nl=$'\n' + +strip_spaces() +{ + [[ "$1" =~ ^[[:space:]]*(.*[^[:space:]])[[:space:]]*$ ]] + echo "${BASH_REMATCH[1]}" +} + +for c in $commits; do + if [ -r "$done_file" ] && grep -q -Fx "$c" "$done_file"; then + continue + fi + + commit_msg="In commit + + $(git log -1 --format='%h ("%s")' $c) + +" + 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') + fixes_msg="Fixes tag + + $fline + +has these problem(s): + +" + sha= + subject= + msg= + [[ "$f" =~ $split_re ]] + sha="${BASH_REMATCH[1]}" + subject="${BASH_REMATCH[2]}" + + if [ -z "$sha" ]; then + printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'No SHA1 recognised' + commit_msg='' + continue + fi + if ! git rev-parse -q --verify "$sha" >/dev/null; then + printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'Target SHA1 does not exist' + commit_msg='' + continue + fi + + if [ "${#sha}" -lt 12 ]; then + msg="${msg:+${msg}${nl}} - SHA1 should be at least 12 digits long" + fi + # reduce the subject to the part between () if there + if [[ "$subject" =~ ^\((.*)\) ]]; then + subject="${BASH_REMATCH[1]}" + elif [[ "$subject" =~ ^\((.*) ]]; then + subject="${BASH_REMATCH[1]}" + msg="${msg:+${msg}${nl}} - Subject has leading but no trailing parentheses" + 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 + subject="${BASH_REMATCH[1]}" + msg="${msg:+${msg}${nl}} - Subject has leading but no trailing quotes" + fi + + subject=$(strip_spaces "$subject") + + target_subject=$(git log -1 --format='%s' "$sha") + target_subject=$(strip_spaces "$target_subject") + + # match with ellipses + case "$subject" in + *...) subject="${subject%...}" + target_subject="${target_subject:0:${#subject}}" + ;; + ...*) subject="${subject#...}" + target_subject="${target_subject: -${#subject}}" + ;; + *\ ...\ *) + s1="${subject% ... *}" + s2="${subject#* ... }" + subject="$s1 $s2" + t1="${target_subject:0:${#s1}}" + t2="${target_subject: -${#s2}}" + target_subject="$t1 $t2" + ;; + esac + subject=$(strip_spaces "$subject") + target_subject=$(strip_spaces "$target_subject") + + if [ "$subject" != "${target_subject:0:${#subject}}" ]; then + msg="${msg:+${msg}${nl}} - Subject does not match target commit subject" + fi + 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 + msg="${msg:+${msg}${nl}} - Target is not an ancestor of this commit" + fi + fi + if [ "$msg" ]; then + printf '%s%s%s\n' "$commit_msg" "$fixes_msg" "$msg" + commit_msg='' + fi + done <<< "$fixes_lines" +done + +exit 0