bin/get-pick-list.sh: rework handing of sha nominations
[mesa.git] / bin / get-pick-list.sh
1 #!/bin/sh
2
3 # Script for generating a list of candidates for cherry-picking to a stable branch
4 #
5 # Usage examples:
6 #
7 # $ bin/get-pick-list.sh
8 # $ bin/get-pick-list.sh > picklist
9 # $ bin/get-pick-list.sh | tee picklist
10 #
11 # The output is as follows:
12 # [nomination_type] commit_sha commit summary
13
14 is_stable_nomination()
15 {
16 git show --summary "$1" | grep -q -i -o "CC:.*mesa-stable"
17 }
18
19 is_typod_nomination()
20 {
21 git show --summary "$1" | grep -q -i -o "CC:.*mesa-dev"
22 }
23
24 fixes=
25
26 # Helper to handle various mistypos of the fixes tag.
27 # The tag string itself is passed as argument and normalised within.
28 #
29 # Resulting string in the global variable "fixes" and contains entries
30 # in the form "fixes:$sha"
31 is_sha_nomination()
32 {
33 fixes=`git show --pretty=medium -s $1 | tr -d "\n" | \
34 sed -e 's/'"$2"'/\nfixes:/Ig' | \
35 grep -Eo 'fixes:[a-f0-9]{8,40}'`
36
37 fixes_count=`echo "$fixes" | grep "fixes:" | wc -l`
38 if test $fixes_count -eq 0; then
39 return 1
40 fi
41 return 0
42 }
43
44 # Checks if at least one of offending commits, listed in the global
45 # "fixes", is in branch.
46 sha_in_range()
47 {
48 fixes_count=`echo "$fixes" | grep "fixes:" | wc -l`
49 while test $fixes_count -gt 0; do
50 # Treat only the current line
51 id=`echo "$fixes" | tail -n $fixes_count | head -n 1 | cut -d : -f 2`
52 fixes_count=$(($fixes_count-1))
53
54 # Be that cherry-picked ...
55 # ... or landed before the branchpoint.
56 if grep -q ^$id already_picked ||
57 grep -q ^$id already_landed ; then
58 return 0
59 fi
60 done
61 return 1
62 }
63
64 is_fixes_nomination()
65 {
66 is_sha_nomination "$1" "fixes:[[:space:]]*"
67 if test $? -eq 0; then
68 return 0
69 fi
70 is_sha_nomination "$1" "fixes[[:space:]]\+"
71 }
72
73 is_brokenby_nomination()
74 {
75 is_sha_nomination "$1" "broken by"
76 }
77
78 is_revert_nomination()
79 {
80 is_sha_nomination "$1" "This reverts commit "
81 }
82
83 # Use the last branchpoint as our limit for the search
84 latest_branchpoint=`git merge-base origin/master HEAD`
85
86 # List all the commits between day 1 and the branch point...
87 git log --reverse --pretty=%H $latest_branchpoint > already_landed
88
89 # ... and the ones cherry-picked.
90 git log --reverse --pretty=medium --grep="cherry picked from commit" $latest_branchpoint..HEAD |\
91 grep "cherry picked from commit" |\
92 sed -e 's/^[[:space:]]*(cherry picked from commit[[:space:]]*//' -e 's/)//' > already_picked
93
94 # Grep for potential candidates
95 git log --reverse --pretty=%H -i --grep='^CC:.*mesa-stable\|^CC:.*mesa-dev\|\<fixes\>\|\<broken by\>\|This reverts commit' $latest_branchpoint..origin/master |\
96 while read sha
97 do
98 # Check to see whether the patch is on the ignore list.
99 if test -f bin/.cherry-ignore; then
100 if grep -q ^$sha bin/.cherry-ignore ; then
101 continue
102 fi
103 fi
104
105 # Check to see if it has already been picked over.
106 if grep -q ^$sha already_picked ; then
107 continue
108 fi
109
110 if is_fixes_nomination "$sha"; then
111 tag=fixes
112 elif is_brokenby_nomination "$sha"; then
113 tag=brokenby
114 elif is_revert_nomination "$sha"; then
115 tag=revert
116 elif is_stable_nomination "$sha"; then
117 tag=stable
118 elif is_typod_nomination "$sha"; then
119 tag=typod
120 else
121 continue
122 fi
123
124 case "$tag" in
125 fixes | brokenby | revert )
126 if ! sha_in_range; then
127 continue
128 fi
129 ;;
130 * )
131 ;;
132 esac
133
134 printf "[ %8s ] " "$tag"
135 git --no-pager show --summary --oneline $sha
136 done
137
138 rm -f already_picked
139 rm -f already_landed