blob: c7e90a88398b90766fdb56843f364c503068790f [file] [log] [blame]
Yvan Rouxa0a33672014-06-02 15:29:43 +02001#!/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# ==============================================================================
12VERSION=4.9
13LINARO_REF_BRANCH=linaro-${VERSION}-branch
14
15DATE=`date +%Y-%m-%d`
16NAME=`git config user.name`
17EMAIL=`git config user.email`
Charles Baylis5f590ee2015-02-25 16:10:21 +000018EDITOR="${EDITOR:-vim}"
Yvan Rouxa0a33672014-06-02 15:29:43 +020019
20# Style
21NC='\e[0m'
22red='\e[0;31m'
23blue='\e[1;34m'
24green='\e[0;32m'
Charles Baylisfcaeede2015-02-25 16:12:16 +000025bold='\e[1m'
Yvan Rouxa0a33672014-06-02 15:29:43 +020026lines=`perl -E 'say "-" x 80'`
27
28# ==============================================================================
29# Functions
30# ==============================================================================
31print_step() {
32 echo -e "${blue}${lines}\n${red}** ${1}\n${blue}${lines}${NC}\n"
33}
34
35print_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
42ask() {
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
50forge_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 Baylisfcaeede2015-02-25 16:12:16 +000056 print_info "${bold}Forged ChangeLog entry:${NC}"
Yvan Rouxa0a33672014-06-02 15:29:43 +020057 cat $2.bcp
Charles Baylisfcaeede2015-02-25 16:12:16 +000058 ask "${bold}Editing [N/y] ?" user_edit
Yvan Rouxa0a33672014-06-02 15:29:43 +020059 if [ "$user_edit" == "y" ]; then
Charles Baylis5f590ee2015-02-25 16:10:21 +000060 "$EDITOR" $2.bcp
Yvan Rouxa0a33672014-06-02 15:29:43 +020061 fi
62}
63
64# ==============================================================================
65print_step "Finding SHA1"
66# ==============================================================================
67SHA1=`git log --format=format:"%H" --grep=trunk@${1} master`
Charles Baylisfcaeede2015-02-25 16:12:16 +000068print_info "${NC}SVN rev ${bold}${1}${NC} SHA1: ${bold}${SHA1}${NC}"
69ask "${bold}Watch the commit [N/y] ?" user_watch
Yvan Rouxa0a33672014-06-02 15:29:43 +020070if [ "$user_watch" == "y" ]; then
71 git show $SHA1
72fi
73
74# ==============================================================================
75print_step "Cherry-picking Revision"
76# ==============================================================================
77git checkout $LINARO_REF_BRANCH
78git cherry-pick -n $SHA1
79
80# ==============================================================================
81print_step "Handling ChangeLogs Conflicts"
82# ==============================================================================
83CHLOGS=`git diff-tree --no-commit-id --name-only -r ${SHA1} | grep ChangeLog`
84for 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
95done
96
97# ==============================================================================
98print_step "Status Checking"
99# ==============================================================================
100git status
Charles Baylisfcaeede2015-02-25 16:12:16 +0000101ask "${bold}Open a Shell [N/y] ?" user_shell
Yvan Rouxa0a33672014-06-02 15:29:43 +0200102if [ "$user_shell" == "y" ]; then
Charles Baylisfcaeede2015-02-25 16:12:16 +0000103 PROMPT_COMMAND="echo -n -e '${bold}[${red}BackFLiP${NC}${bold}]${NC} '" bash
Yvan Rouxa0a33672014-06-02 15:29:43 +0200104fi
105
106# ==============================================================================
107print_step "Branch/Commit/Push/Review"
108# ==============================================================================
109bname=${VERSION}-backport-${1}
Charles Baylisfcaeede2015-02-25 16:12:16 +0000110ask "${bold}Create backport branch [Y/n] ?" user_bc
Yvan Rouxa0a33672014-06-02 15:29:43 +0200111if [ "$user_bc" != "n" ]; then
Charles Baylisfcaeede2015-02-25 16:12:16 +0000112 ask "${bold}Change name (${blue}${bname}${NC}${bold}) [N/y] ?" user_bname
Yvan Rouxa0a33672014-06-02 15:29:43 +0200113 if [ "$user_bname" == "y" ]; then
Charles Baylisfcaeede2015-02-25 16:12:16 +0000114 ask "${bold}Enter name :" bname
Yvan Rouxa0a33672014-06-02 15:29:43 +0200115 fi
116 git checkout -b ${bname} origin/${LINARO_REF_BRANCH}
117
Charles Baylisfcaeede2015-02-25 16:12:16 +0000118 ask "${bold}Commit backport [Y/n] ?" user_commit
Yvan Rouxa0a33672014-06-02 15:29:43 +0200119 if [ "$user_commit" != "n" ]; then
120 git commit
121
Charles Baylisfcaeede2015-02-25 16:12:16 +0000122 ask "${bold}Create patch [Y/n] ?" user_patch
Yvan Rouxa0a33672014-06-02 15:29:43 +0200123 if [ "$user_patch" != "n" ]; then
124 git format-patch -o ../ --suffix=.${bname}.patch -1
125 fi
126
Charles Baylisfcaeede2015-02-25 16:12:16 +0000127 ask "${bold}Push ${bname} branch [Y/n] ?" user_push
Yvan Rouxa0a33672014-06-02 15:29:43 +0200128 if [ "$user_push" != "n" ]; then
129 git push origin ${bname}:${bname}
130
Charles Baylisfcaeede2015-02-25 16:12:16 +0000131 ask "${bold}Request review (amend commit) [Y/n] ?" user_review
Yvan Rouxa0a33672014-06-02 15:29:43 +0200132 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
139fi
140
141# ==============================================================================
Charles Baylisfcaeede2015-02-25 16:12:16 +0000142ask "${bold}Abort and Cleanup [N/y] ?" user_abort
Yvan Rouxa0a33672014-06-02 15:29:43 +0200143# ==============================================================================
144if [ "$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
154fi