Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set +e
- #set -x
- BRANCHMAINLINE=mainline
- BRANCH318=stable/linux-3.18.y
- BRANCH44=stable/linux-4.4.y
- BRANCH49=stable/linux-4.9.y
- BRANCH53=stable/linux-5.3.y
- WORKTREERELPATH=.. # Worktree location with respect to current repo
- declare -a CANDIDATES
- BRANCHES=""
- usage()
- {
- echo "Usage: $0 [[-if <find-backports-output.txt>] | [-o|-ib <backport-patches-output.txt>]]"
- }
- while [ $# -gt 0 ]; do
- case $1 in
- -if|--find-backports-file|--found)
- FBINFILE=$2
- shift
- ;;
- -ib|--backport-patches-file|--read)
- BPINFILE=$2
- shift
- ;;
- -o|--output|--out)
- OUTFILE=$2
- shift
- ;;
- *)
- echo "Unrecognised parameter $1"
- usage
- exit 1
- ;;
- esac
- shift
- done
- print_red()
- {
- echo -e "\e[01;31m$@\e[0m"
- }
- print_green()
- {
- echo -e "\e[01;32m$@\e[0m"
- }
- print_blue()
- {
- echo -e "\e[01;34m$@\e[0m"
- }
- was_backported_to_stable()
- {
- branch=$1; shift
- subject=${@}
- if git log --no-merges --oneline --grep "${subject}" ${branch} 2>&1 | grep -q "${subject}"; then
- return 0
- fi
- return 1
- }
- find_candidates()
- {
- while read add del sha subject; do
- declare -a branches_present; unset branches_present
- declare -a branches_missing; unset branches_missing
- local candidate; candidate=""
- if [ "${add}" == "$" ] || [ "${add}" == "#" ]; then
- continue
- fi
- # Patch should be in Mainline
- mainline=$(git branch --contains ${sha} | sed 's/+/ /' | sed 's/*/ /')
- if ! echo $mainline | grep -q ${BRANCHMAINLINE}; then
- print_red "${sha} ${subject}\n Does not appear to be a Mainline commit?"
- continue
- fi
- # Quick search: Was patch commited *before* the base release i.e. does it have the same SHA as Mainline
- readarray branches_present < <(git branch --contains ${sha} | sed 's/+/ /' | sed 's/*/ /')
- if echo ${branches_present[*]} | \
- grep ${BRANCH318} | grep ${BRANCH44} | grep ${BRANCH49} | grep -q ${BRANCH53}; then
- print_green "\u2714 OC: ${sha} ${subject}"; # Commit is in all Stable branches
- continue
- fi
- # Fast then slow search
- for b in ${BRANCH318} ${BRANCH44} ${BRANCH49} ${BRANCH53}; do
- # Fast: Did we inherit this patch?
- if ! echo ${branches_present[*]} | grep -q ${b}; then
- # Slow: Was this patch backported?
- if ! was_backported_to_stable ${b} ${subject}; then
- # Commit is missing from this branch - lets backport it
- branches_missing+=(${b})
- fi
- fi
- done
- if ! echo ${branches_missing[*]} | \
- grep -q "${BRANCH318}\|${BRANCH44}\|${BRANCH49}\|${BRANCH53}"; then
- print_green "\u2714 BP: ${sha} ${subject}"; # Commit is in all Stable branches
- continue
- elif ! echo ${branches_present[*]} | \
- grep -q "${BRANCH318}\|${BRANCH44}\|${BRANCH49}\|${BRANCH53}"; then
- print_red "\u2718 NO: ${sha} ${subject}" # Commit is not in any Stable branch
- candidate=true
- else
- print_blue "${sha} ${subject}" # Commit is in at least one, but not all Stable branches
- for b in ${BRANCH318} ${BRANCH44} ${BRANCH49} ${BRANCH53}; do
- if echo ${branches_missing[*]} | grep -q ${b}; then
- print_red " \u2718 NO: ${b}"
- candidate=true
- else
- if echo ${branches_present[*]} | grep -q ${b}; then
- print_green " \u2714 OC: ${b}"
- else
- print_green " \u2714 BP: ${b}"
- fi
- fi
- done
- fi
- if [ "${candidate}" == "true" ]; then
- CANDIDATES+=("${sha} ${branches_missing[*]}")
- fi
- done < <(cat ${FBINFILE})
- }
- save_candidates()
- {
- if [ "${OUTFILE}" == "" ]; then
- return
- fi
- rm ${OUTFILE} 2>&1 > /dev/null || true
- touch ${OUTFILE}
- for c in "${CANDIDATES[@]}"; do
- echo ${c} >> ${OUTFILE}
- done
- }
- read_candidates()
- {
- while read -r line; do
- CANDIDATES+=("${line}")
- done < ${BPINFILE}
- }
- review_candidates()
- {
- for c in "${CANDIDATES[@]}"; do
- sha=$(echo ${c} | cut -d' ' -f1)
- branches_missing=$(echo ${c} | cut -d' ' -f2-)
- subject=$(git log --pretty=%s -n1 ${sha})
- git --no-pager show ${sha}
- print_red "\nDoes this patch look like Stable material (y/N)?"
- read choice
- if [ "${choice}" != "y" ] && [ "${choice}" != "Y" ]; then
- continue
- fi
- for b in ${BRANCH318} ${BRANCH44} ${BRANCH49} ${BRANCH53}; do
- if echo ${branches_missing} | grep -q ${b}; then
- worktree=${WORKTREERELPATH}/${b}
- print_blue "Attempting to apply '${subject}' to ${b}"
- print_blue "Moving to $worktree"
- pushd $worktree
- git cherry-pick -s ${sha} || \
- { print_red "Failed, try to apply it manually and press return OR Ctrl+c"; read; }
- popd
- fi
- done
- done
- }
- if [ ! -d drivers ] || [ ! -f MAINTAINERS ]; then
- print_red "Not in the Kernel Git repository"
- exit 1
- fi
- if [ "${FBINFILE}" != "" ] && [ ! -f "${FBINFILE}" ]; then
- echo "${FBINFILE} does not exist"
- usage
- exit 1
- fi
- if [ "${BPINFILE}" != "" ] && [ ! -f "${BPINFILE}" ]; then
- echo "${BPINFILE} does not exist"
- usage
- exit 1
- fi
- # All Mainline and Stable branches need to exist locally
- git branch | grep -q "${BRANCHMAINLINE}" || { print_red "$BRANCHMAINLINE not found locally"; exit 1; }
- git branch | grep -q "${BRANCH318}" || { print_red "$BRANCH318 not found locally"; exit 1; }
- git branch | grep -q "${BRANCH44}" || { print_red "$BRANCH44 not found locally"; exit 1; }
- git branch | grep -q "${BRANCH49}" || { print_red "$BRANCH49 not found locally"; exit 1; }
- git branch | grep -q "${BRANCH53}" || { print_red "$BRANCH53 not found locally"; exit 1; }
- if [ "${FBINFILE}" != "" ]; then
- find_candidates
- save_candidates
- elif [ "${BPINFILE}" != "" ]; then
- read_candidates
- else
- usage
- exit 1
- fi
- review_candidates
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement