]> git.ozlabs.org Git - next-scripts/blob - check_fixes
update to_build_host a bit
[next-scripts] / check_fixes
1 #!/bin/bash
2
3 shopt -s extglob
4
5 if [ "$#" -lt 1 ]; then
6         printf 'Usage: %s <commit range>\n', "$0" 1>&2
7         exit 1
8 fi
9
10 commits=$(git rev-list --no-merges -i --grep='^[[:space:]]*Fixes:' "$@")
11 if [ -z "$commits" ]; then
12         exit 0
13 fi
14
15 # This should be a git tree that contains *only* Linus' tree
16 Linus_tree="${HOME}/kernels/linus.git"
17
18 split_re='^([Cc][Oo][Mm][Mm][Ii][Tt])?[[:space:]]*([[:xdigit:]]{5,})([[:space:]]*)(.*)$'
19 nl=$'\n'
20 tab=$'\t'
21
22 # Strip the leading and training spaces from a string
23 strip_spaces()
24 {
25         local str="${1##*([[:space:]])}"
26         str="${str%%*([[:space:]])}"
27         echo "$str"
28 }
29
30 for c in $commits; do
31
32         printf -v commit_msg 'In commit\n\n  %s\n\n' \
33                 "$(git log -1 --format='%h ("%s")' "$c")"
34
35         readarray -t fixes_lines < <(git log -1 --format='%B' "$c" |
36                                         grep -i '^[[:space:]]*Fixes:')
37         fixes_lines=( "${fixes_lines[@]##*([[:space:]])}" )
38         fixes_lines=( "${fixes_lines[@]%%*([[:space:]])}" )
39
40         for fline in "${fixes_lines[@]}"; do
41                 f="${fline##[Ff][Ii][Xx][Ee][Ss]:*([[:space:]])}"
42                 printf -v fixes_msg 'Fixes tag\n\n  %s\n\nhas these problem(s):\n\n' "$fline"
43                 sha=
44                 subject=
45                 msg=
46                 if [[ "$f" =~ $split_re ]]; then
47                         first="${BASH_REMATCH[1]}"
48                         sha="${BASH_REMATCH[2]}"
49                         spaces="${BASH_REMATCH[3]}"
50                         subject="${BASH_REMATCH[4]}"
51                         if [ "$first" ]; then
52                                 msg="${msg:+${msg}${nl}}  - leading word '$first' unexpected"
53                         fi
54                         if [ -z "$subject" ]; then
55                                 msg="${msg:+${msg}${nl}}  - missing subject"
56                         elif [ -z "$spaces" ]; then
57                                 msg="${msg:+${msg}${nl}}  - missing space between the SHA1 and the subject"
58                         fi
59                 else
60                         printf '%s%s  - %s\n' "$commit_msg" "$fixes_msg" 'No SHA1 recognised'
61                         commit_msg=''
62                         continue
63                 fi
64                 if ! git rev-parse -q --verify "$sha" >/dev/null; then
65                         printf '%s%s  - %s\n' "$commit_msg" "$fixes_msg" 'Target SHA1 does not exist'
66                         commit_msg=''
67                         continue
68                 fi
69
70                 if [ "${#sha}" -lt 12 ]; then
71                         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\")."
72                 fi
73                 # reduce the subject to the part between () if there
74                 if [[ "$subject" =~ ^\((.*)\) ]]; then
75                         subject="${BASH_REMATCH[1]}"
76                 elif [[ "$subject" =~ ^\((.*) ]]; then
77                         subject="${BASH_REMATCH[1]}"
78                         msg="${msg:+${msg}${nl}}  - Subject has leading but no trailing parentheses"
79                 fi
80
81                 # strip matching quotes at the start and end of the subject
82                 # the unicode characters in the classes are
83                 # U+201C LEFT DOUBLE QUOTATION MARK
84                 # U+201D RIGHT DOUBLE QUOTATION MARK
85                 # U+2018 LEFT SINGLE QUOTATION MARK
86                 # U+2019 RIGHT SINGLE QUOTATION MARK
87                 re1=$'^[\"\u201C](.*)[\"\u201D]$'
88                 re2=$'^[\'\u2018](.*)[\'\u2019]$'
89                 re3=$'^[\"\'\u201C\u2018](.*)$'
90                 if [[ "$subject" =~ $re1 ]]; then
91                         subject="${BASH_REMATCH[1]}"
92                 elif [[ "$subject" =~ $re2 ]]; then
93                         subject="${BASH_REMATCH[1]}"
94                 elif [[ "$subject" =~ $re3 ]]; then
95                         subject="${BASH_REMATCH[1]}"
96                         msg="${msg:+${msg}${nl}}  - Subject has leading but no trailing quotes"
97                 fi
98
99                 subject=$(strip_spaces "$subject")
100
101                 target_subject=$(git log -1 --format='%s' "$sha")
102                 target_subject=$(strip_spaces "$target_subject")
103
104                 # match with ellipses
105                 case "$subject" in
106                 *...)   subject="${subject%...}"
107                         target_subject="${target_subject:0:${#subject}}"
108                         ;;
109                 ...*)   subject="${subject#...}"
110                         target_subject="${target_subject: -${#subject}}"
111                         ;;
112                 *\ ...\ *)
113                         s1="${subject% ... *}"
114                         s2="${subject#* ... }"
115                         subject="$s1 $s2"
116                         t1="${target_subject:0:${#s1}}"
117                         t2="${target_subject: -${#s2}}"
118                         target_subject="$t1 $t2"
119                         ;;
120                 esac
121                 subject=$(strip_spaces "$subject")
122                 target_subject=$(strip_spaces "$target_subject")
123
124                 if [ "$subject" != "${target_subject:0:${#subject}}" ]; then
125                         msg="${msg:+${msg}${nl}}  - Subject does not match target commit subject${nl}    Just use${nl}${tab}git log -1 --format='Fixes: %h (\"%s\")'"
126                 fi
127                 lsha=$(cd "$Linus_tree" && git rev-parse -q --verify "$sha")
128                 if [ -z "$lsha" ]; then
129                         count=$(git rev-list --count "$sha".."$c")
130                         if [ "$count" -eq 0 ]; then
131                                 msg="${msg:+${msg}${nl}}  - Target is not an ancestor of this commit"
132                         fi
133                 fi
134                 if [ "$msg" ]; then
135                         printf '%s%s%s\n' "$commit_msg" "$fixes_msg" "$msg"
136                         commit_msg=''
137                 fi
138         done
139 done
140
141 exit 0