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"
16 split_re='^([Cc][Oo][Mm][Mm][Ii][Tt])?[[:space:]]*([[:xdigit:]]{5,})([[:space:]]*)(.*)$'
19 # Strip the leading and training spaces from a string
22 [[ "$1" =~ ^[[:space:]]*(.*[^[:space:]])[[:space:]]*$ ]]
23 echo "${BASH_REMATCH[1]}"
28 commit_log=$(git log -1 --format='%h ("%s")' "$c")
35 fixes_lines=$(git log -1 --format='%B' "$c" |
36 grep -i '^[[:space:]]*Fixes:')
38 while read -r fline; do
39 [[ "$fline" =~ ^[[:space:]]*[Ff][Ii][Xx][Ee][Ss]:[[:space:]]*(.*)$ ]]
40 f="${BASH_REMATCH[1]}"
51 if [[ "$f" =~ $split_re ]]; then
52 first="${BASH_REMATCH[1]}"
53 sha="${BASH_REMATCH[2]}"
54 spaces="${BASH_REMATCH[3]}"
55 subject="${BASH_REMATCH[4]}"
57 msg="${msg:+${msg}${nl}} - leading word '$first' unexpected"
59 if [ -z "$subject" ]; then
60 msg="${msg:+${msg}${nl}} - missing subject"
61 elif [ -z "$spaces" ]; then
62 msg="${msg:+${msg}${nl}} - missing space between the SHA1 and the subject"
65 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'No SHA1 recognised'
69 if ! git rev-parse -q --verify "$sha" >/dev/null; then
70 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'Target SHA1 does not exist'
75 if [ "${#sha}" -lt 12 ]; then
76 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\")."
78 # reduce the subject to the part between () if there
79 if [[ "$subject" =~ ^\((.*)\) ]]; then
80 subject="${BASH_REMATCH[1]}"
81 elif [[ "$subject" =~ ^\((.*) ]]; then
82 subject="${BASH_REMATCH[1]}"
83 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing parentheses"
86 # strip matching quotes at the start and end of the subject
87 # the unicode characters in the classes are
88 # U+201C LEFT DOUBLE QUOTATION MARK
89 # U+201D RIGHT DOUBLE QUOTATION MARK
90 # U+2018 LEFT SINGLE QUOTATION MARK
91 # U+2019 RIGHT SINGLE QUOTATION MARK
92 re1=$'^[\"\u201C](.*)[\"\u201D]$'
93 re2=$'^[\'\u2018](.*)[\'\u2019]$'
94 re3=$'^[\"\'\u201C\u2018](.*)$'
95 if [[ "$subject" =~ $re1 ]]; then
96 subject="${BASH_REMATCH[1]}"
97 elif [[ "$subject" =~ $re2 ]]; then
98 subject="${BASH_REMATCH[1]}"
99 elif [[ "$subject" =~ $re3 ]]; then
100 subject="${BASH_REMATCH[1]}"
101 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing quotes"
104 subject=$(strip_spaces "$subject")
106 target_subject=$(git log -1 --format='%s' "$sha")
107 target_subject=$(strip_spaces "$target_subject")
109 # match with ellipses
111 *...) subject="${subject%...}"
112 target_subject="${target_subject:0:${#subject}}"
114 ...*) subject="${subject#...}"
115 target_subject="${target_subject: -${#subject}}"
118 s1="${subject% ... *}"
119 s2="${subject#* ... }"
121 t1="${target_subject:0:${#s1}}"
122 t2="${target_subject: -${#s2}}"
123 target_subject="$t1 $t2"
126 subject=$(strip_spaces "$subject")
127 target_subject=$(strip_spaces "$target_subject")
129 if [ "$subject" != "${target_subject:0:${#subject}}" ]; then
130 msg="${msg:+${msg}${nl}} - Subject does not match target commit subject"
132 lsha=$(cd "$Linus_tree" && git rev-parse -q --verify "$sha")
133 if [ -z "$lsha" ]; then
134 count=$(git rev-list --count "$sha".."$c")
135 if [ "$count" -eq 0 ]; then
136 msg="${msg:+${msg}${nl}} - Target is not an ancestor of this commit"
140 printf '%s%s%s\n' "$commit_msg" "$fixes_msg" "$msg"
143 done <<< "$fixes_lines"