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_re1='^([[:xdigit:]]{5,})[[:space:]]+(.*)$'
16 split_re2='^([[:xdigit:]]{5,})[[:space:]]*(.*)$'
17 split_re3='^([Cc][Oo][Mm][Mm][Ii][Tt])[[:space:]]*([[:xdigit:]]{5,})[[:space:]]*(.*)$'
20 # Strip the leading and training spaces from a string
23 [[ "$1" =~ ^[[:space:]]*(.*[^[:space:]])[[:space:]]*$ ]]
24 echo "${BASH_REMATCH[1]}"
29 commit_log=$(git log -1 --format='%h ("%s")' "$c")
36 fixes_lines=$(git log -1 --format='%B' "$c" |
37 grep -i '^[[:space:]]*Fixes:')
39 while read -r fline; do
40 [[ "$fline" =~ ^[[:space:]]*[Ff][Ii][Xx][Ee][Ss]:[[:space:]]*(.*)$ ]]
41 f="${BASH_REMATCH[1]}"
52 [[ "$f" =~ $split_re1 ]]
53 sha="${BASH_REMATCH[1]}"
54 subject="${BASH_REMATCH[2]}"
56 if [ -z "$sha" ]; then
57 [[ "$f" =~ $split_re2 ]]
58 sha="${BASH_REMATCH[1]}"
59 subject="${BASH_REMATCH[2]}"
60 if [ -z "$sha" ]; then
61 [[ "$f" =~ $split_re3 ]]
62 sha="${BASH_REMATCH[2]}"
63 subject="${BASH_REMATCH[3]}"
64 msg="${msg:+${msg}${nl}} - leading word '${BASH_REMATCH[1]}' unexpected"
67 if [ -z "$sha" ]; then
68 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'No SHA1 recognised'
72 if ! git rev-parse -q --verify "$sha" >/dev/null; then
73 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'Target SHA1 does not exist'
78 if [ "${#sha}" -lt 12 ]; then
79 msg="${msg:+${msg}${nl}} - SHA1 should be at least 12 digits long"
81 # reduce the subject to the part between () if there
82 if [[ "$subject" =~ ^\((.*)\) ]]; then
83 subject="${BASH_REMATCH[1]}"
84 elif [[ "$subject" =~ ^\((.*) ]]; then
85 subject="${BASH_REMATCH[1]}"
86 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing parentheses"
89 # strip matching quotes at the start and end of the subject
90 # the unicode characters in the classes are
91 # U+201C LEFT DOUBLE QUOTATION MARK
92 # U+201D RIGHT DOUBLE QUOTATION MARK
93 # U+2018 LEFT SINGLE QUOTATION MARK
94 # U+2019 RIGHT SINGLE QUOTATION MARK
95 re1=$'^[\"\u201C](.*)[\"\u201D]$'
96 re2=$'^[\'\u2018](.*)[\'\u2019]$'
97 re3=$'^[\"\'\u201C\u2018](.*)$'
98 if [[ "$subject" =~ $re1 ]]; then
99 subject="${BASH_REMATCH[1]}"
100 elif [[ "$subject" =~ $re2 ]]; then
101 subject="${BASH_REMATCH[1]}"
102 elif [[ "$subject" =~ $re3 ]]; then
103 subject="${BASH_REMATCH[1]}"
104 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing quotes"
107 subject=$(strip_spaces "$subject")
109 target_subject=$(git log -1 --format='%s' "$sha")
110 target_subject=$(strip_spaces "$target_subject")
112 # match with ellipses
114 *...) subject="${subject%...}"
115 target_subject="${target_subject:0:${#subject}}"
117 ...*) subject="${subject#...}"
118 target_subject="${target_subject: -${#subject}}"
121 s1="${subject% ... *}"
122 s2="${subject#* ... }"
124 t1="${target_subject:0:${#s1}}"
125 t2="${target_subject: -${#s2}}"
126 target_subject="$t1 $t2"
129 subject=$(strip_spaces "$subject")
130 target_subject=$(strip_spaces "$target_subject")
132 if [ "$subject" != "${target_subject:0:${#subject}}" ]; then
133 msg="${msg:+${msg}${nl}} - Subject does not match target commit subject"
135 lsha=$(cd "$Linus_tree" && git rev-parse -q --verify "$sha")
136 if [ -z "$lsha" ]; then
137 count=$(git rev-list --count "$sha".."$c")
138 if [ "$count" -eq 0 ]; then
139 msg="${msg:+${msg}${nl}} - Target is not an ancestor of this commit"
143 printf '%s%s%s\n' "$commit_msg" "$fixes_msg" "$msg"
146 done <<< "$fixes_lines"