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:]]+(.*)$'
18 # Strip the leading and training spaces from a string
21 [[ "$1" =~ ^[[:space:]]*(.*[^[:space:]])[[:space:]]*$ ]]
22 echo "${BASH_REMATCH[1]}"
27 commit_log=$(git log -1 --format='%h ("%s")' "$c")
34 fixes_lines=$(git log -1 --format='%B' "$c" |
35 grep -i '^[[:space:]]*Fixes:')
37 while read -r fline; do
38 [[ "$fline" =~ ^[[:space:]]*[Ff][Ii][Xx][Ee][Ss]:[[:space:]]*(.*)$ ]]
39 f="${BASH_REMATCH[1]}"
50 [[ "$f" =~ $split_re ]]
51 sha="${BASH_REMATCH[1]}"
52 subject="${BASH_REMATCH[2]}"
54 if [ -z "$sha" ]; then
55 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'No SHA1 recognised'
59 if ! git rev-parse -q --verify "$sha" >/dev/null; then
60 printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'Target SHA1 does not exist'
65 if [ "${#sha}" -lt 12 ]; then
66 msg="${msg:+${msg}${nl}} - SHA1 should be at least 12 digits long"
68 # reduce the subject to the part between () if there
69 if [[ "$subject" =~ ^\((.*)\) ]]; then
70 subject="${BASH_REMATCH[1]}"
71 elif [[ "$subject" =~ ^\((.*) ]]; then
72 subject="${BASH_REMATCH[1]}"
73 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing parentheses"
76 # strip matching quotes at the start and end of the subject
77 # the unicode characters in the classes are
78 # U+201C LEFT DOUBLE QUOTATION MARK
79 # U+201D RIGHT DOUBLE QUOTATION MARK
80 # U+2018 LEFT SINGLE QUOTATION MARK
81 # U+2019 RIGHT SINGLE QUOTATION MARK
82 re1=$'^[\"\u201C](.*)[\"\u201D]$'
83 re2=$'^[\'\u2018](.*)[\'\u2019]$'
84 re3=$'^[\"\'\u201C\u2018](.*)$'
85 if [[ "$subject" =~ $re1 ]]; then
86 subject="${BASH_REMATCH[1]}"
87 elif [[ "$subject" =~ $re2 ]]; then
88 subject="${BASH_REMATCH[1]}"
89 elif [[ "$subject" =~ $re3 ]]; then
90 subject="${BASH_REMATCH[1]}"
91 msg="${msg:+${msg}${nl}} - Subject has leading but no trailing quotes"
94 subject=$(strip_spaces "$subject")
96 target_subject=$(git log -1 --format='%s' "$sha")
97 target_subject=$(strip_spaces "$target_subject")
101 *...) subject="${subject%...}"
102 target_subject="${target_subject:0:${#subject}}"
104 ...*) subject="${subject#...}"
105 target_subject="${target_subject: -${#subject}}"
108 s1="${subject% ... *}"
109 s2="${subject#* ... }"
111 t1="${target_subject:0:${#s1}}"
112 t2="${target_subject: -${#s2}}"
113 target_subject="$t1 $t2"
116 subject=$(strip_spaces "$subject")
117 target_subject=$(strip_spaces "$target_subject")
119 if [ "$subject" != "${target_subject:0:${#subject}}" ]; then
120 msg="${msg:+${msg}${nl}} - Subject does not match target commit subject"
122 lsha=$(cd "$Linus_tree" && git rev-parse -q --verify "$sha")
123 if [ -z "$lsha" ]; then
124 count=$(git rev-list --count "$sha".."$c")
125 if [ "$count" -eq 0 ]; then
126 msg="${msg:+${msg}${nl}} - Target is not an ancestor of this commit"
130 printf '%s%s%s\n' "$commit_msg" "$fixes_msg" "$msg"
133 done <<< "$fixes_lines"