Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============================================================================== |
| 4 | # *** BackFLiP (a.k.a BACKporting Fun with LInaro People) *** |
| 5 | # |
| 6 | # Usage: backflip rev_number |
| 7 | # ============================================================================== |
| 8 | |
| 9 | # ============================================================================== |
| 10 | # Configuration |
| 11 | # ============================================================================== |
| 12 | VERSION=4.9 |
| 13 | LINARO_REF_BRANCH=linaro-${VERSION}-branch |
| 14 | |
| 15 | DATE=`date +%Y-%m-%d` |
| 16 | NAME=`git config user.name` |
| 17 | EMAIL=`git config user.email` |
Charles Baylis | 5f590ee | 2015-02-25 16:10:21 +0000 | [diff] [blame] | 18 | EDITOR="${EDITOR:-vim}" |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 19 | |
| 20 | # Style |
| 21 | NC='\e[0m' |
| 22 | red='\e[0;31m' |
| 23 | blue='\e[1;34m' |
| 24 | green='\e[0;32m' |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 25 | bold='\e[1m' |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 26 | lines=`perl -E 'say "-" x 80'` |
| 27 | |
| 28 | # ============================================================================== |
| 29 | # Functions |
| 30 | # ============================================================================== |
| 31 | print_step() { |
| 32 | echo -e "${blue}${lines}\n${red}** ${1}\n${blue}${lines}${NC}\n" |
| 33 | } |
| 34 | |
| 35 | print_info() { |
| 36 | echo -e "${blue}** ${NC}${1}" |
| 37 | } |
| 38 | |
| 39 | # arg1 : a sentence |
| 40 | # arg2 : a variable |
| 41 | # print arg1 and gather user input in arg2 |
| 42 | ask() { |
| 43 | echo -n -e "${blue}** ${NC}${1} ${NC}" |
| 44 | eval "read ${2}" |
| 45 | } |
| 46 | |
| 47 | # arg1 : svn rev number |
| 48 | # arg2 : ChangeLog file |
| 49 | # Create ChangeLog entry for arg1 in arg2.bcp |
| 50 | forge_entry() { |
| 51 | echo -e $DATE" "$NAME" <"$EMAIL">\n\n\tBackport from trunk r"$1"." >> $2.bcp |
| 52 | git show --format=oneline ${SHA1} -- $2 \ |
| 53 | | grep ^+ \ |
| 54 | | sed -e '1d' -e 's:^+::' \ |
| 55 | | awk '$1 ~ /^2.*$/ {print "\t"$0} $1 !~ /^2.*$/ {print $0}' >> $2.bcp |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 56 | print_info "${bold}Forged ChangeLog entry:${NC}" |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 57 | cat $2.bcp |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 58 | ask "${bold}Editing [N/y] ?" user_edit |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 59 | if [ "$user_edit" == "y" ]; then |
Charles Baylis | 5f590ee | 2015-02-25 16:10:21 +0000 | [diff] [blame] | 60 | "$EDITOR" $2.bcp |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 61 | fi |
| 62 | } |
| 63 | |
| 64 | # ============================================================================== |
| 65 | print_step "Finding SHA1" |
| 66 | # ============================================================================== |
| 67 | SHA1=`git log --format=format:"%H" --grep=trunk@${1} master` |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 68 | print_info "${NC}SVN rev ${bold}${1}${NC} SHA1: ${bold}${SHA1}${NC}" |
| 69 | ask "${bold}Watch the commit [N/y] ?" user_watch |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 70 | if [ "$user_watch" == "y" ]; then |
| 71 | git show $SHA1 |
| 72 | fi |
| 73 | |
| 74 | # ============================================================================== |
| 75 | print_step "Cherry-picking Revision" |
| 76 | # ============================================================================== |
| 77 | git checkout $LINARO_REF_BRANCH |
| 78 | git cherry-pick -n $SHA1 |
| 79 | |
| 80 | # ============================================================================== |
| 81 | print_step "Handling ChangeLogs Conflicts" |
| 82 | # ============================================================================== |
| 83 | CHLOGS=`git diff-tree --no-commit-id --name-only -r ${SHA1} | grep ChangeLog` |
| 84 | for i in $CHLOGS; do |
| 85 | print_info "${green}$i" |
| 86 | # Revert ChangeLog corruption |
| 87 | git reset -q HEAD $i |
| 88 | git checkout $i |
| 89 | # Create ChangeLog entry |
| 90 | forge_entry $1 $i |
| 91 | # Add it in Linaro ChangeLog |
| 92 | cat $i.linaro >> $i.bcp |
| 93 | mv $i.bcp $i.linaro |
| 94 | git add $i.linaro |
| 95 | done |
| 96 | |
| 97 | # ============================================================================== |
| 98 | print_step "Status Checking" |
| 99 | # ============================================================================== |
| 100 | git status |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 101 | ask "${bold}Open a Shell [N/y] ?" user_shell |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 102 | if [ "$user_shell" == "y" ]; then |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 103 | PROMPT_COMMAND="echo -n -e '${bold}[${red}BackFLiP${NC}${bold}]${NC} '" bash |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 104 | fi |
| 105 | |
| 106 | # ============================================================================== |
| 107 | print_step "Branch/Commit/Push/Review" |
| 108 | # ============================================================================== |
| 109 | bname=${VERSION}-backport-${1} |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 110 | ask "${bold}Create backport branch [Y/n] ?" user_bc |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 111 | if [ "$user_bc" != "n" ]; then |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 112 | ask "${bold}Change name (${blue}${bname}${NC}${bold}) [N/y] ?" user_bname |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 113 | if [ "$user_bname" == "y" ]; then |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 114 | ask "${bold}Enter name :" bname |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 115 | fi |
| 116 | git checkout -b ${bname} origin/${LINARO_REF_BRANCH} |
| 117 | |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 118 | ask "${bold}Commit backport [Y/n] ?" user_commit |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 119 | if [ "$user_commit" != "n" ]; then |
| 120 | git commit |
| 121 | |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 122 | ask "${bold}Create patch [Y/n] ?" user_patch |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 123 | if [ "$user_patch" != "n" ]; then |
| 124 | git format-patch -o ../ --suffix=.${bname}.patch -1 |
| 125 | fi |
| 126 | |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 127 | ask "${bold}Push ${bname} branch [Y/n] ?" user_push |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 128 | if [ "$user_push" != "n" ]; then |
| 129 | git push origin ${bname}:${bname} |
| 130 | |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 131 | ask "${bold}Request review (amend commit) [Y/n] ?" user_review |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 132 | if [ "$user_review" != "n" ]; then |
| 133 | git commit --amend |
| 134 | git review $LINARO_REF_BRANCH |
| 135 | git checkout $LINARO_REF_BRANCH |
| 136 | fi |
| 137 | fi |
| 138 | fi |
| 139 | fi |
| 140 | |
| 141 | # ============================================================================== |
Charles Baylis | fcaeede | 2015-02-25 16:12:16 +0000 | [diff] [blame^] | 142 | ask "${bold}Abort and Cleanup [N/y] ?" user_abort |
Yvan Roux | a0a3367 | 2014-06-02 15:29:43 +0200 | [diff] [blame] | 143 | # ============================================================================== |
| 144 | if [ "$user_abort" == "y" ]; then |
| 145 | git reset --hard |
| 146 | git checkout ${LINARO_REF_BRANCH} |
| 147 | if [ "$user_bc" != "n" ]; then |
| 148 | git branch -D ${bname} |
| 149 | if [ "$user_push" != "n" ]; then |
| 150 | git push origin :${bname} |
| 151 | fi |
| 152 | fi |
| 153 | exit 0 |
| 154 | fi |