Emil Velikov | 32be878 | 2017-02-23 17:05:50 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Emil Velikov | 389478c | 2017-02-11 16:47:56 +0000 | [diff] [blame] | 2 | |
| 3 | # Script for generating a list of candidates [referenced by a Fixes tag] for |
| 4 | # cherry-picking to a stable branch |
| 5 | # |
| 6 | # Usage examples: |
| 7 | # |
| 8 | # $ bin/get-fixes-pick-list.sh |
| 9 | # $ bin/get-fixes-pick-list.sh > picklist |
| 10 | # $ bin/get-fixes-pick-list.sh | tee picklist |
| 11 | |
| 12 | # Use the last branchpoint as our limit for the search |
| 13 | latest_branchpoint=`git merge-base origin/master HEAD` |
| 14 | |
| 15 | # List all the commits between day 1 and the branch point... |
| 16 | git log --reverse --pretty=%H $latest_branchpoint > already_landed |
| 17 | |
| 18 | # ... and the ones cherry-picked. |
| 19 | git log --reverse --grep="cherry picked from commit" $latest_branchpoint..HEAD |\ |
| 20 | grep "cherry picked from commit" |\ |
| 21 | sed -e 's/^[[:space:]]*(cherry picked from commit[[:space:]]*//' -e 's/)//' > already_picked |
| 22 | |
| 23 | # Grep for commits with Fixes tag |
| 24 | git log --reverse --pretty=%H -i --grep="fixes:" $latest_branchpoint..origin/master |\ |
| 25 | while read sha |
| 26 | do |
Juan A. Suarez Romero | 99b4163 | 2017-04-05 20:14:22 +0200 | [diff] [blame] | 27 | # Check to see whether the patch is on the ignore list ... |
| 28 | if [ -f bin/.cherry-ignore ] ; then |
| 29 | if grep -q ^$sha bin/.cherry-ignore ; then |
| 30 | continue |
| 31 | fi |
| 32 | fi |
| 33 | |
Andres Gomez | b7af0dd | 2017-05-08 20:57:35 +0300 | [diff] [blame] | 34 | # Skip if it has been already cherry-picked. |
| 35 | if grep -q ^$sha already_picked ; then |
| 36 | continue |
| 37 | fi |
| 38 | |
Andres Gomez | 5d87667 | 2017-05-13 03:11:08 +0300 | [diff] [blame] | 39 | # Place every "fixes:" tag on its own line and join with the next word |
| 40 | # on its line or a later one. |
| 41 | fixes=`git show -s $sha | tr -d "\n" | sed -e 's/fixes:[[:space:]]*/\nfixes:/Ig' | grep "fixes:" | sed -e 's/\(fixes:[a-zA-Z0-9]*\).*$/\1/'` |
| 42 | |
Emil Velikov | 389478c | 2017-02-11 16:47:56 +0000 | [diff] [blame] | 43 | # For each one try to extract the tag |
Andres Gomez | 5d87667 | 2017-05-13 03:11:08 +0300 | [diff] [blame] | 44 | fixes_count=`echo "$fixes" | wc -l` |
Andres Gomez | b7af0dd | 2017-05-08 20:57:35 +0300 | [diff] [blame] | 45 | warn=`(test $fixes_count -gt 1 && echo $fixes_count) || echo 0` |
Andres Gomez | 77306e2 | 2017-05-06 17:09:35 +0300 | [diff] [blame] | 46 | while [ $fixes_count -gt 0 ] ; do |
Andres Gomez | 5d87667 | 2017-05-13 03:11:08 +0300 | [diff] [blame] | 47 | # Treat only the current line |
| 48 | id=`echo "$fixes" | tail -n $fixes_count | head -n 1 | cut -d : -f 2` |
Andres Gomez | 77306e2 | 2017-05-06 17:09:35 +0300 | [diff] [blame] | 49 | fixes_count=$(($fixes_count-1)) |
Emil Velikov | 389478c | 2017-02-11 16:47:56 +0000 | [diff] [blame] | 50 | |
Andres Gomez | 77306e2 | 2017-05-06 17:09:35 +0300 | [diff] [blame] | 51 | # Bail out if we cannot find suitable id. |
| 52 | # Any specific validation the $id is valid and not some junk, is |
| 53 | # implied with the follow up code |
| 54 | if [ "x$id" = x ] ; then |
Emil Velikov | 389478c | 2017-02-11 16:47:56 +0000 | [diff] [blame] | 55 | continue |
| 56 | fi |
| 57 | |
Andres Gomez | 77306e2 | 2017-05-06 17:09:35 +0300 | [diff] [blame] | 58 | # Check if the offending commit is in branch. |
| 59 | |
| 60 | # Be that cherry-picked ... |
| 61 | # ... or landed before the branchpoint. |
| 62 | if grep -q ^$id already_picked || |
| 63 | grep -q ^$id already_landed ; then |
| 64 | |
Andres Gomez | 77306e2 | 2017-05-06 17:09:35 +0300 | [diff] [blame] | 65 | printf "Commit \"%s\" fixes %s\n" \ |
| 66 | "`git log -n1 --pretty=oneline $sha`" \ |
| 67 | "$id" |
Andres Gomez | b7af0dd | 2017-05-08 20:57:35 +0300 | [diff] [blame] | 68 | warn=$(($warn-1)) |
Andres Gomez | 77306e2 | 2017-05-06 17:09:35 +0300 | [diff] [blame] | 69 | fi |
| 70 | |
| 71 | done |
Emil Velikov | 389478c | 2017-02-11 16:47:56 +0000 | [diff] [blame] | 72 | |
Andres Gomez | b7af0dd | 2017-05-08 20:57:35 +0300 | [diff] [blame] | 73 | if [ $warn -gt 0 ] ; then |
| 74 | printf "WARNING: Commit \"%s\" has more than one Fixes tag\n" \ |
| 75 | "`git log -n1 --pretty=oneline $sha`" |
| 76 | fi |
| 77 | |
Emil Velikov | 389478c | 2017-02-11 16:47:56 +0000 | [diff] [blame] | 78 | done |
| 79 | |
| 80 | rm -f already_picked |
| 81 | rm -f already_landed |