3 if [ "$#" -lt 1 ]; then
4 printf 'Usage: %s <commit range>\n', "$0" 1>&2
8 commits=$(git rev-list --no-merges -i --grep='^[[:space:]]*Fixes:' "$@")
9 if [ -z "$commits" ]; then
13 Linus_tree="${HOME}/kernels/linus.git"
14 done_file="${HOME}/tmp/check_fixes_done"
15 split_re='^([[:xdigit:]]+)[[:space:]]+(.*)$'
20 [[ "$1" =~ ^[[:space:]]*(.*[^[:space:]])[[:space:]]*$ ]]
21 echo "${BASH_REMATCH[1]}"
25 if [ -r "$done_file" ] && grep -q -Fx "$c" "$done_file"; then
31 $(git log -1 --format='%h ("%s")' $c)
34 fixes_lines=$(git log -1 --format='%B' "$c" |
35 grep -i '^[[:space:]]*Fixes:')
38 f=$(echo "$fline" | sed 's/^[[:space:]]*Fixes:[[:space:]]*//i')
49 [[ "$f" =~ $split_re ]]
50 sha="${BASH_REMATCH[1]}"
51 subject="${BASH_REMATCH[2]}"
53 if [ -z "$sha" ]; then
54 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'No SHA1 recognised'
58 if ! git rev-parse -q --verify "$sha" >/dev/null; then
59 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'Target SHA1 does not exist'
64 if [ "${#sha}" -lt 12 ]; then
65 msg="${msg:+${msg}${nl}} - SHA1 should be at least 12 digits long"
67 # reduce the subject to the part between () if there
68 if [[ "$subject" =~ ^\((.*)\) ]]; then
69 subject="${BASH_REMATCH[1]}"
70 elif [[ "$subject" =~ ^\((.*) ]]; then
71 subject="${BASH_REMATCH[1]}"
72 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing parentheses"
75 # strip matching quotes at the start and end of the subject
76 re='^(['\''"])(.*)\1$'
77 if [[ "$subject" =~ $re ]]; then
78 subject="${BASH_REMATCH[2]}"
79 elif [[ "$subject" =~ ^[\'\"](.*)$ ]]; then
80 subject="${BASH_REMATCH[1]}"
81 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing quotes"
84 subject=$(strip_spaces "$subject")
86 target_subject=$(git log -1 --format='%s' "$sha")
87 target_subject=$(strip_spaces "$target_subject")
91 *...) subject="${subject%...}"
92 target_subject="${target_subject:0:${#subject}}"
94 ...*) subject="${subject#...}"
95 target_subject="${target_subject: -${#subject}}"
98 s1="${subject% ... *}"
99 s2="${subject#* ... }"
101 t1="${target_subject:0:${#s1}}"
102 t2="${target_subject: -${#s2}}"
103 target_subject="$t1 $t2"
106 subject=$(strip_spaces "$subject")
107 target_subject=$(strip_spaces "$target_subject")
109 if [ "$subject" != "${target_subject:0:${#subject}}" ]; then
110 msg="${msg:+${msg}${nl}} - Subject does not match target commit subject"
112 lsha=$(cd $Linus_tree; git rev-parse -q --verify "$sha")
113 if [ -z "$lsha" ]; then
114 count=$(git rev-list --count "$sha".."$c")
115 if [ "$count" -eq 0 ]; then
116 msg="${msg:+${msg}${nl}} - Target is not an ancestor of this commit"
120 printf '%s%s%s\n' "$commit_msg" "$fixes_msg" "$msg"
123 done <<< "$fixes_lines"