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 # This should be a git tree that contains *only* Linus' tree
14 Linus_tree="${HOME}/kernels/linus.git"
15 split_re='^([[:xdigit:]]+)[[:space:]]+(.*)$'
20 [[ "$1" =~ ^[[:space:]]*(.*[^[:space:]])[[:space:]]*$ ]]
21 echo "${BASH_REMATCH[1]}"
26 commit_log=$(git log -1 --format='%h ("%s")' "$c")
27 commit_msg=$(printf 'In commit\n\n %s\n\n' "$commit_log")
29 fixes_lines=$(git log -1 --format='%B' "$c" |
30 grep -i '^[[:space:]]*Fixes:')
32 while read -r fline; do
33 f=$(echo "$fline" | sed 's/^[[:space:]]*Fixes:[[:space:]]*//i')
34 fixes_msg=$(printf 'Fixes tag\n\n %s\n\n has these problem(s):\n\n' "$fline")
38 [[ "$f" =~ $split_re ]]
39 sha="${BASH_REMATCH[1]}"
40 subject="${BASH_REMATCH[2]}"
42 if [ -z "$sha" ]; then
43 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'No SHA1 recognised'
47 if ! git rev-parse -q --verify "$sha" >/dev/null; then
48 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'Target SHA1 does not exist'
53 if [ "${#sha}" -lt 12 ]; then
54 msg="${msg:+${msg}${nl}} - SHA1 should be at least 12 digits long"
56 # reduce the subject to the part between () if there
57 if [[ "$subject" =~ ^\((.*)\) ]]; then
58 subject="${BASH_REMATCH[1]}"
59 elif [[ "$subject" =~ ^\((.*) ]]; then
60 subject="${BASH_REMATCH[1]}"
61 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing parentheses"
64 # strip matching quotes at the start and end of the subject
65 # the second characters in the classes are
66 # U+201C LEFT DOUBLE QUOTATION MARK
67 # U+201D RIGHT DOUBLE QUOTATION MARK
68 # U+2018 LEFT SINGLE QUOTATION MARK
69 # U+2019 RIGHT SINGLE QUOTATION MARK
70 re1=$'^[\"\u201C](.*)[\"\u201D]$'
71 re2=$'^[\'\u2018](.*)[\'\u2019]$'
72 re3=$'^[\"\'\u201C\u2018](.*)$'
73 if [[ "$subject" =~ $re1 ]]; then
74 subject="${BASH_REMATCH[1]}"
75 elif [[ "$subject" =~ $re2 ]]; then
76 subject="${BASH_REMATCH[1]}"
77 elif [[ "$subject" =~ $re3 ]]; then
78 subject="${BASH_REMATCH[1]}"
79 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing quotes"
82 subject=$(strip_spaces "$subject")
84 target_subject=$(git log -1 --format='%s' "$sha")
85 target_subject=$(strip_spaces "$target_subject")
89 *...) subject="${subject%...}"
90 target_subject="${target_subject:0:${#subject}}"
92 ...*) subject="${subject#...}"
93 target_subject="${target_subject: -${#subject}}"
96 s1="${subject% ... *}"
97 s2="${subject#* ... }"
99 t1="${target_subject:0:${#s1}}"
100 t2="${target_subject: -${#s2}}"
101 target_subject="$t1 $t2"
104 subject=$(strip_spaces "$subject")
105 target_subject=$(strip_spaces "$target_subject")
107 if [ "$subject" != "${target_subject:0:${#subject}}" ]; then
108 msg="${msg:+${msg}${nl}} - Subject does not match target commit subject"
110 lsha=$(cd "$Linus_tree" && git rev-parse -q --verify "$sha")
111 if [ -z "$lsha" ]; then
112 count=$(git rev-list --count "$sha".."$c")
113 if [ "$count" -eq 0 ]; then
114 msg="${msg:+${msg}${nl}} - Target is not an ancestor of this commit"
118 printf '%s%s%s\n' "$commit_msg" "$fixes_msg" "$msg"
121 done <<< "$fixes_lines"