blob: 2077c4e4df721c9bb227e49efe41307a0a30c2b2 [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
if [ $(git status -uno --porcelain | wc -l) -eq 0 ]; then
git reset --hard
return 1
fi
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 [ $? -eq 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)
stable commit-in-tree $orig_cmt
if [ $? -eq 1 ]; then
continue
fi
# 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
if [ $(git status -uno --porcelain | wc -l) -eq 0 ]; then
git reset --hard
continue
fi
echo "Cherry pick failed. Fix, commit (or reset) and exit."
stable deps $i 10
/bin/bash
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/bash
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