Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set +e
  4. #set -x
  5.  
  6. BRANCHMAINLINE=mainline
  7. BRANCH318=stable/linux-3.18.y
  8. BRANCH44=stable/linux-4.4.y
  9. BRANCH49=stable/linux-4.9.y
  10. BRANCH53=stable/linux-5.3.y
  11.  
  12. WORKTREERELPATH=.. # Worktree location with respect to current repo
  13.  
  14. declare -a CANDIDATES
  15. BRANCHES=""
  16.  
  17. usage()
  18. {
  19. echo "Usage: $0 [[-if <find-backports-output.txt>] | [-o|-ib <backport-patches-output.txt>]]"
  20. }
  21.  
  22. while [ $# -gt 0 ]; do
  23. case $1 in
  24. -if|--find-backports-file|--found)
  25. FBINFILE=$2
  26. shift
  27. ;;
  28. -ib|--backport-patches-file|--read)
  29. BPINFILE=$2
  30. shift
  31. ;;
  32. -o|--output|--out)
  33. OUTFILE=$2
  34. shift
  35. ;;
  36. *)
  37. echo "Unrecognised parameter $1"
  38. usage
  39. exit 1
  40. ;;
  41. esac
  42. shift
  43. done
  44.  
  45. print_red()
  46. {
  47. echo -e "\e[01;31m$@\e[0m"
  48. }
  49.  
  50. print_green()
  51. {
  52. echo -e "\e[01;32m$@\e[0m"
  53. }
  54.  
  55. print_blue()
  56. {
  57. echo -e "\e[01;34m$@\e[0m"
  58. }
  59.  
  60. was_backported_to_stable()
  61. {
  62. branch=$1; shift
  63. subject=${@}
  64.  
  65. if git log --no-merges --oneline --grep "${subject}" ${branch} 2>&1 | grep -q "${subject}"; then
  66. return 0
  67. fi
  68.  
  69. return 1
  70. }
  71.  
  72. find_candidates()
  73. {
  74. while read add del sha subject; do
  75. declare -a branches_present; unset branches_present
  76. declare -a branches_missing; unset branches_missing
  77. local candidate; candidate=""
  78.  
  79. if [ "${add}" == "$" ] || [ "${add}" == "#" ]; then
  80. continue
  81. fi
  82.  
  83. # Patch should be in Mainline
  84. mainline=$(git branch --contains ${sha} | sed 's/+/ /' | sed 's/*/ /')
  85. if ! echo $mainline | grep -q ${BRANCHMAINLINE}; then
  86. print_red "${sha} ${subject}\n Does not appear to be a Mainline commit?"
  87. continue
  88. fi
  89.  
  90. # Quick search: Was patch commited *before* the base release i.e. does it have the same SHA as Mainline
  91. readarray branches_present < <(git branch --contains ${sha} | sed 's/+/ /' | sed 's/*/ /')
  92. if echo ${branches_present[*]} | \
  93. grep ${BRANCH318} | grep ${BRANCH44} | grep ${BRANCH49} | grep -q ${BRANCH53}; then
  94. print_green "\u2714 OC: ${sha} ${subject}"; # Commit is in all Stable branches
  95. continue
  96. fi
  97.  
  98. # Fast then slow search
  99. for b in ${BRANCH318} ${BRANCH44} ${BRANCH49} ${BRANCH53}; do
  100. # Fast: Did we inherit this patch?
  101. if ! echo ${branches_present[*]} | grep -q ${b}; then
  102. # Slow: Was this patch backported?
  103. if ! was_backported_to_stable ${b} ${subject}; then
  104. # Commit is missing from this branch - lets backport it
  105. branches_missing+=(${b})
  106. fi
  107. fi
  108. done
  109.  
  110. if ! echo ${branches_missing[*]} | \
  111. grep -q "${BRANCH318}\|${BRANCH44}\|${BRANCH49}\|${BRANCH53}"; then
  112. print_green "\u2714 BP: ${sha} ${subject}"; # Commit is in all Stable branches
  113. continue
  114. elif ! echo ${branches_present[*]} | \
  115. grep -q "${BRANCH318}\|${BRANCH44}\|${BRANCH49}\|${BRANCH53}"; then
  116. print_red "\u2718 NO: ${sha} ${subject}" # Commit is not in any Stable branch
  117. candidate=true
  118. else
  119. print_blue "${sha} ${subject}" # Commit is in at least one, but not all Stable branches
  120.  
  121. for b in ${BRANCH318} ${BRANCH44} ${BRANCH49} ${BRANCH53}; do
  122. if echo ${branches_missing[*]} | grep -q ${b}; then
  123. print_red " \u2718 NO: ${b}"
  124. candidate=true
  125. else
  126. if echo ${branches_present[*]} | grep -q ${b}; then
  127. print_green " \u2714 OC: ${b}"
  128. else
  129. print_green " \u2714 BP: ${b}"
  130. fi
  131. fi
  132. done
  133. fi
  134.  
  135. if [ "${candidate}" == "true" ]; then
  136. CANDIDATES+=("${sha} ${branches_missing[*]}")
  137. fi
  138.  
  139. done < <(cat ${FBINFILE})
  140. }
  141.  
  142.  
  143. save_candidates()
  144. {
  145. if [ "${OUTFILE}" == "" ]; then
  146. return
  147. fi
  148.  
  149. rm ${OUTFILE} 2>&1 > /dev/null || true
  150. touch ${OUTFILE}
  151.  
  152. for c in "${CANDIDATES[@]}"; do
  153. echo ${c} >> ${OUTFILE}
  154. done
  155. }
  156.  
  157. read_candidates()
  158. {
  159. while read -r line; do
  160. CANDIDATES+=("${line}")
  161. done < ${BPINFILE}
  162. }
  163.  
  164. review_candidates()
  165. {
  166. for c in "${CANDIDATES[@]}"; do
  167. sha=$(echo ${c} | cut -d' ' -f1)
  168. branches_missing=$(echo ${c} | cut -d' ' -f2-)
  169. subject=$(git log --pretty=%s -n1 ${sha})
  170.  
  171. git --no-pager show ${sha}
  172. print_red "\nDoes this patch look like Stable material (y/N)?"
  173. read choice
  174.  
  175. if [ "${choice}" != "y" ] && [ "${choice}" != "Y" ]; then
  176. continue
  177. fi
  178.  
  179. for b in ${BRANCH318} ${BRANCH44} ${BRANCH49} ${BRANCH53}; do
  180. if echo ${branches_missing} | grep -q ${b}; then
  181. worktree=${WORKTREERELPATH}/${b}
  182. print_blue "Attempting to apply '${subject}' to ${b}"
  183. print_blue "Moving to $worktree"
  184. pushd $worktree
  185. git cherry-pick -s ${sha} || \
  186. { print_red "Failed, try to apply it manually and press return OR Ctrl+c"; read; }
  187. popd
  188. fi
  189. done
  190. done
  191. }
  192.  
  193. if [ ! -d drivers ] || [ ! -f MAINTAINERS ]; then
  194. print_red "Not in the Kernel Git repository"
  195. exit 1
  196. fi
  197.  
  198. if [ "${FBINFILE}" != "" ] && [ ! -f "${FBINFILE}" ]; then
  199. echo "${FBINFILE} does not exist"
  200. usage
  201. exit 1
  202. fi
  203.  
  204. if [ "${BPINFILE}" != "" ] && [ ! -f "${BPINFILE}" ]; then
  205. echo "${BPINFILE} does not exist"
  206. usage
  207. exit 1
  208. fi
  209.  
  210. # All Mainline and Stable branches need to exist locally
  211. git branch | grep -q "${BRANCHMAINLINE}" || { print_red "$BRANCHMAINLINE not found locally"; exit 1; }
  212. git branch | grep -q "${BRANCH318}" || { print_red "$BRANCH318 not found locally"; exit 1; }
  213. git branch | grep -q "${BRANCH44}" || { print_red "$BRANCH44 not found locally"; exit 1; }
  214. git branch | grep -q "${BRANCH49}" || { print_red "$BRANCH49 not found locally"; exit 1; }
  215. git branch | grep -q "${BRANCH53}" || { print_red "$BRANCH53 not found locally"; exit 1; }
  216.  
  217. if [ "${FBINFILE}" != "" ]; then
  218. find_candidates
  219. save_candidates
  220. elif [ "${BPINFILE}" != "" ]; then
  221. read_candidates
  222. else
  223. usage
  224. exit 1
  225. fi
  226.  
  227. review_candidates
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement