blob: 9fa2a15cbb82b82ff56f7423cbd88938f40c6ac1 [file] [log] [blame]
#!/bin/bash
#
# Try to grab commits from one stable tree into another, stopping to fix
# backports if required.
#
. common
function pick_one {
# Let's try cherry-picking the given commit first.
git cherry-pick --strategy=recursive -Xpatience -x $1 &> /dev/null
if [ $? -gt "0" ]; then
git reset --hard
# That didn't work? Let's try that with every variation of the commit
# in other stable trees.
for i in $(stable-find-alts $1); do
git cherry-pick --strategy=recursive -Xpatience -x $i &> /dev/null
if [ $? = "0" ]; then
return 0
fi
git reset --hard
done
# Still no? Let's go back to the original commit and hand it off to
# the user.
git cherry-pick --strategy=recursive -Xpatience -x $1 &> /dev/null
fi
return $?
}
function do_one {
for i in $(git log --no-merges --format="%H" $1 $2 | tac); do
subj=$(git log -1 --format="%s" $i)
# Let's grab the mainline commit id, this is useful if the version tag
# doesn't exist in the commit we're looking at but exists upstream.
orig_cmt=$(git log --no-merges --format="%H" -F --grep "$subj" origin/master | tail -n1)
# If the commit doesn't apply for us, skip it
check_relevant $orig_cmt
if [ $? -eq "0" ]; then
continue
fi
pick_one $i
if [ $? -gt 0 ] ; then
echo "Cherry pick failed. Fix, commit (or reset) and exit."
/bin/sh
continue
fi
# If we didn't find the commit upstream then this must be a custom commit
# in the given tree - make sure the user checks this commit.
if [ "$orig_cmt" = "" ] ; then
msg="Custom"
orig_cmt=$(git rev-parse HEAD)
echo "Custom commit, please double-check!"
/bin/sh
fi
stable-make-pretty $orig_cmt $msg
done
}
if [ "$#" -ne 1 ] && [ "$#" -ne 2 ]; then
echo "Usage: stable steal-commits <commit range> [branch]"
exit 1
fi
do_one $1 $2