summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYvan Roux <yvan.roux@linaro.org>2014-06-02 15:29:43 +0200
committerYvan Roux <yvan.roux@linaro.org>2014-06-02 15:29:43 +0200
commita0a3367dd991b71ee5c055daa2766f1c489bc58e (patch)
tree2d92b9004e7e1b131fa94581d8cd38fa8b17b10c
downloadbackflip-a0a3367dd991b71ee5c055daa2766f1c489bc58e.tar.gz
Initial import of the backflip script.
-rwxr-xr-xbackflip154
1 files changed, 154 insertions, 0 deletions
diff --git a/backflip b/backflip
new file mode 100755
index 0000000..3afd3ce
--- /dev/null
+++ b/backflip
@@ -0,0 +1,154 @@
+#!/bin/bash
+
+# ==============================================================================
+# *** BackFLiP (a.k.a BACKporting Fun with LInaro People) ***
+#
+# Usage: backflip rev_number
+# ==============================================================================
+
+# ==============================================================================
+# Configuration
+# ==============================================================================
+VERSION=4.9
+LINARO_REF_BRANCH=linaro-${VERSION}-branch
+
+DATE=`date +%Y-%m-%d`
+NAME=`git config user.name`
+EMAIL=`git config user.email`
+EDITOR=vim
+
+# Style
+NC='\e[0m'
+red='\e[0;31m'
+blue='\e[1;34m'
+green='\e[0;32m'
+white='\e[1;37m'
+lines=`perl -E 'say "-" x 80'`
+
+# ==============================================================================
+# Functions
+# ==============================================================================
+print_step() {
+ echo -e "${blue}${lines}\n${red}** ${1}\n${blue}${lines}${NC}\n"
+}
+
+print_info() {
+ echo -e "${blue}** ${NC}${1}"
+}
+
+# arg1 : a sentence
+# arg2 : a variable
+# print arg1 and gather user input in arg2
+ask() {
+ echo -n -e "${blue}** ${NC}${1} ${NC}"
+ eval "read ${2}"
+}
+
+# arg1 : svn rev number
+# arg2 : ChangeLog file
+# Create ChangeLog entry for arg1 in arg2.bcp
+forge_entry() {
+ echo -e $DATE" "$NAME" <"$EMAIL">\n\n\tBackport from trunk r"$1"." >> $2.bcp
+ git show --format=oneline ${SHA1} -- $2 \
+ | grep ^+ \
+ | sed -e '1d' -e 's:^+::' \
+ | awk '$1 ~ /^2.*$/ {print "\t"$0} $1 !~ /^2.*$/ {print $0}' >> $2.bcp
+ print_info "${white}Forged ChangeLog entry:${NC}"
+ cat $2.bcp
+ ask "${white}Editing [N/y] ?" user_edit
+ if [ "$user_edit" == "y" ]; then
+ $EDITOR $2.bcp
+ fi
+}
+
+# ==============================================================================
+print_step "Finding SHA1"
+# ==============================================================================
+SHA1=`git log --format=format:"%H" --grep=trunk@${1} master`
+print_info "${NC}SVN rev ${white}${1}${NC} SHA1: ${white}${SHA1}${NC}"
+ask "${white}Watch the commit [N/y] ?" user_watch
+if [ "$user_watch" == "y" ]; then
+ git show $SHA1
+fi
+
+# ==============================================================================
+print_step "Cherry-picking Revision"
+# ==============================================================================
+git checkout $LINARO_REF_BRANCH
+git cherry-pick -n $SHA1
+
+# ==============================================================================
+print_step "Handling ChangeLogs Conflicts"
+# ==============================================================================
+CHLOGS=`git diff-tree --no-commit-id --name-only -r ${SHA1} | grep ChangeLog`
+for i in $CHLOGS; do
+ print_info "${green}$i"
+ # Revert ChangeLog corruption
+ git reset -q HEAD $i
+ git checkout $i
+ # Create ChangeLog entry
+ forge_entry $1 $i
+ # Add it in Linaro ChangeLog
+ cat $i.linaro >> $i.bcp
+ mv $i.bcp $i.linaro
+ git add $i.linaro
+done
+
+# ==============================================================================
+print_step "Status Checking"
+# ==============================================================================
+git status
+ask "${white}Open a Shell [N/y] ?" user_shell
+if [ "$user_shell" == "y" ]; then
+ PROMPT_COMMAND="echo -n -e '${white}[${red}BackFLiP${white}] '" bash
+fi
+
+# ==============================================================================
+print_step "Branch/Commit/Push/Review"
+# ==============================================================================
+bname=${VERSION}-backport-${1}
+ask "${white}Create backport branch [Y/n] ?" user_bc
+if [ "$user_bc" != "n" ]; then
+ ask "${white}Change name (${blue}${bname}${white}) [N/y] ?" user_bname
+ if [ "$user_bname" == "y" ]; then
+ ask "${white}Enter name :" bname
+ fi
+ git checkout -b ${bname} origin/${LINARO_REF_BRANCH}
+
+ ask "${white}Commit backport [Y/n] ?" user_commit
+ if [ "$user_commit" != "n" ]; then
+ git commit
+
+ ask "${white}Create patch [Y/n] ?" user_patch
+ if [ "$user_patch" != "n" ]; then
+ git format-patch -o ../ --suffix=.${bname}.patch -1
+ fi
+
+ ask "${white}Push ${bname} branch [Y/n] ?" user_push
+ if [ "$user_push" != "n" ]; then
+ git push origin ${bname}:${bname}
+
+ ask "${white}Request review (amend commit) [Y/n] ?" user_review
+ if [ "$user_review" != "n" ]; then
+ git commit --amend
+ git review $LINARO_REF_BRANCH
+ git checkout $LINARO_REF_BRANCH
+ fi
+ fi
+ fi
+fi
+
+# ==============================================================================
+ask "${white}Abort and Cleanup [N/y] ?" user_abort
+# ==============================================================================
+if [ "$user_abort" == "y" ]; then
+ git reset --hard
+ git checkout ${LINARO_REF_BRANCH}
+ if [ "$user_bc" != "n" ]; then
+ git branch -D ${bname}
+ if [ "$user_push" != "n" ]; then
+ git push origin :${bname}
+ fi
+ fi
+ exit 0
+fi